avoid full page postback on dropdow selected index changed...

INNET 1 Reputation point
2021-06-02T17:24:22.817+00:00

I have a gridview wrapped around update panel. I have two template fields in gridview as follows:

<asp:TemplateField HeaderText="User">

                                    <ItemTemplate>  
                                          
                                         <asp:DropDownList ID="ddlUsers" runat="server"  
                                                        AutoPostBack="true" OnSelectedIndexChanged="ddlUsers_SelectedIndexChanged"/>  
                                         
                
                                    </ItemTemplate>  
                                </asp:TemplateField>  
                                <asp:TemplateField HeaderText="Status" >  
                                    <ItemTemplate>  
                                        <div class="panel panel-default">  
                                            <div class="panel-heading"><asp:Literal runat="server" ID="lblSelectedUser" /></div>  
                                            <ul class="list-group">  
                                                <li class="list-group-item"><span class="strong">ID</span>: <asp:Literal runat="server" ID="lblId" /></li>  
                                                <li class="list-group-item"><span class="strong">Name</span>: <asp:Literal runat="server" ID="lblFullName"></asp:Literal></li>  
                                                <li class="list-group-item"><span class="strong">Email</span>: <asp:Literal runat="server" ID="lblEmail"></asp:Literal></li>  
                                            </ul>  
                                        </div>  
                                    </ItemTemplate>  
                                </asp:TemplateField>  

I can't set autopostback to "false" for the ddlUsers as I am updating the literal controls text values for the other template field properties in the ddlUsers_SelectedIndexChanged event. Is there a way to not cause a postback but still run the indexchanged event to update the other values in literal controls?

The dropdown text value is stored as Lastname,FirstName [ID] (Email) and somtimes as Lastname(Middle),Firstname [ID] (Email)

Is there a way to update the lblId, lblFullName and lblEmail to be the values from the dropdown in javascript and change the row for that gridview to be a different color without the selectedIndexChanged event firing?
so if the dropdown selected index is changed to "Gabriel, Josh [12345] (gabrielJ@test .com)" then the lblId would be 12345, lblFullName text would be Gabriel, Josh and lblEmail.text would be gabrielJ@test .com and the row backgroudn color would be lightgreen or something to denote that dropdown selection has been changed for the row.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,598 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,418 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Luis Remuñán 21 Reputation points
    2021-06-03T00:48:44.7+00:00

    Hello,

    If you can post the entire updatepanel it will be helpful. It could be a lot of things, maybe you haven't configured the trigger element of the update panel the to fire with the dropdownlist event, i.e.:
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddlUsers"
    EventName="SelectedIndexChanged" />
    </Triggers>

    Regards

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.