Click here to Skip to main content
15,914,419 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to Visible/hide dropdownlist based on the selection of some other dropdownlist value
that is placed inside the ajax update panel


I have tried like this...

XML
<asp:UpdatePanel ID="upSetSession" runat="server">
                             <ContentTemplate>
                              <asp:DropDownList ID="ddl_position" runat="server" class="feedback_textfield" AutoPostBack="true" OnSelectedIndexChanged="ddl_SelectedIndexChanged" >
                                  <asp:ListItem>Select</asp:ListItem>
                                  <asp:ListItem>Prime Minister</asp:ListItem>
                                  <asp:ListItem>Chief Minister</asp:ListItem>
                                  <asp:ListItem>President</asp:ListItem>
                                  <asp:ListItem>Governor</asp:ListItem>
                              </asp:DropDownList>


                              </ContentTemplate>
                              <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddl_position"
                    EventName="SelectedIndexChanged" />
            </Triggers>
         </asp:UpdatePanel>
                                  </td><td width="10">
                                  <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
                                      ControlToValidate="ddl_position" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
                                  </td>
                        </tr>

                        <asp:Panel ID="state" runat="server">

                        <tr >

                          <td width="80" align="left" valign="middle">Select State</td>
                          <td width="16" align="center" valign="middle">:</td>
                          <td width="150" align="left" valign="middle">
                              <asp:DropDownList ID="ddl_state" runat="server" class="feedback_textfield" >
                                  <asp:ListItem>Select</asp:ListItem>
                                  
                              </asp:DropDownList>
                                  </td><td width="10">
                                  <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server"
                                      ControlToValidate="ddl_state" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
                                  </td>


                        </tr>
                        </asp:Panel>



code file...


C#
protected void Page_Load(object sender, EventArgs e)
    {
        state.Visible = false;

    }
    protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_position.SelectedItem.Value == "Chief Minister" || ddl_position.SelectedItem.Value == "Governor")
        {

            state.Visible = true;

        }

        else
        {

            state.Visible = false;
        }
    }



But its not working..
can anyone kindly tell me how to do this...

Thanks in Advance...
Posted
Comments
JITHU.P 29-May-14 11:59am    
you know when we use the ajax it make flicker free page

so we can use the viewstate and solve the problem

Hello ,
I think you forgot to set the IsPostBack property in the PageLoad event . As a result the panel is always invisible .
So , modify the PageLoad event by this way
protected void Page_Load(object sender, EventArgs e)
    {
       if(!IsPostBack)
        { 
         state.Visible = false;
        }
    }

thanks
 
Share this answer
 
Comments
priya dharshan 29-May-14 8:33am    
I have tried with if(!IsPostBack) also...its not working....
Animesh Datta 29-May-14 8:37am    
I think it is better , if you remove the visibility option from PageLoad and set False in designmode .
priya dharshan 29-May-14 8:49am    
I have tried that also..not working...
Animesh Datta 29-May-14 9:11am    
Put the Panel inside the ContentTemplate of UpdatePanel . other wise it will not work .
check this link
http://www.dotnetfox.com/articles/updatepanel-with-triggers-in-Asp-Net-1090.aspx
I have Used nested update panel....
XML
<asp:UpdatePanel ID="upSetSession" runat="server">
                            <ContentTemplate>
                             <asp:DropDownList ID="ddl_position" runat="server" class="feedback_textfield" AutoPostBack="true" OnSelectedIndexChanged="ddl_SelectedIndexChanged" >
                                 <asp:ListItem>Select</asp:ListItem>
                                 <asp:ListItem>Prime Minister</asp:ListItem>
                                 <asp:ListItem>Chief Minister</asp:ListItem>
                                 <asp:ListItem>President</asp:ListItem>
                                 <asp:ListItem>Governor</asp:ListItem>
                             </asp:DropDownList>






                                 </td><td width="10">
                                 <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
                                     ControlToValidate="ddl_position" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
                                 </td>
                       </tr> <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                            <ContentTemplate>
                       <asp:Panel ID="state" runat="server" Visible="false">

                       <tr >


                             <asp:DropDownList ID="ddl_state" runat="server" class="feedback_textfield" >
                                 <asp:ListItem>Select State</asp:ListItem>
                                 <asp:ListItem>Prime Minister</asp:ListItem>
                                 <asp:ListItem>Chief Minister</asp:ListItem>
                                 <asp:ListItem>President</asp:ListItem>
                                 <asp:ListItem>Governor</asp:ListItem>
                             </asp:DropDownList>

                                 <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server"
                                     ControlToValidate="ddl_state" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>



                       </tr>
                       </asp:Panel>
                       </ContentTemplate>
                       </asp:UpdatePanel>
                       </ContentTemplate>
                             <Triggers>
               <asp:AsyncPostBackTrigger ControlID="ddl_position"
                   EventName="SelectedIndexChanged" />
           </Triggers>
        </asp:UpdatePanel>
 
Share this answer
 

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