Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have many dropdownlists and textboxes in a single page. I have done validations on textboxes. Each dropdownlist populate another dropdownlist. The problem is, all existing validation messages are disappear when selectedindexchanged event fired. How to populate second dropdownlist without postback?
Posted
Updated 15-Mar-17 3:00am

hi,
you can make use of Updatepanel in your page, this will not postback your page. Check this i have used it. The ControlID given in the <asp:AsyncPostBackTrigger> is the Control on whose indexchanging changes the values in the second dropdown. update panel is to be applied on the second dropdown where the values has to be reflected without postback. in the example below year dropdown gets filled as per the process selected.

ASP.NET
<asp:UpdatePanel ID="upSetSession" runat="server">
             <ContentTemplate>
         <asp:DropDownList ID="ddlyear" runat="server" AppendDataBoundItems="True" CssClass="textarea" ValidationGroup="validate">
             <asp:ListItem>Please Select</asp:ListItem>
         </asp:DropDownList>
                 <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="validateyear" ControlToValidate="ddlyear" Display="Dynamic" ErrorMessage="*" ForeColor="#FF3300" ToolTip="*" ValidationGroup="validate">*</asp:CustomValidator>
         </ContentTemplate>
              <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddlprocess" 
                    EventName="SelectedIndexChanged" />
            </Triggers>
       </asp:UpdatePanel>
 
Share this answer
 
v3
 
Share this answer
 
Comments
Member 9018012 24-Feb-15 10:53am    
I used ajax call updatepanel and triggers.
Using ajax call and Web Method you can bind dropdown wiht out postback
 
Share this answer
 
Comments
Member 9018012 25-Feb-15 4:05am    
Thanks. I have 7 dropdownlists which populates another dropdownlist. Is there any way to reduce code?
set validation group on validation control and button and use update panel for asynchronously bind drop down on selected Chang Event of another drop down
use update panel like
first declare ScriptManager your page

ASP.NET
<asp:ScriptManager ID="ScriptManager1" runat="server">
   </asp:ScriptManager>

ASP.NET
<asp:dropdownlist id="ddl1" runat="server" enableviewstate="False" >
</asp:dropdownlist>   
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
   <ContentTemplate>
          <asp:dropdownlist id="ddl2" runat="server" enableviewstate="False">
          </asp:dropdownlist>                                     
   </ContentTemplate>
   <Triggers>
   <asp:AsyncPostBackTrigger ControlID="ddl1" EventName="SelectedIndexChanged" />
   </Triggers>
</asp:UpdatePanel>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900