Click here to Skip to main content
12,240,300 members (60,758 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#3.0 C# ASP.NET
Hi Frnds,
Below code i have two Panel.Inside drop down change event i need to change panel change.but page also getting refresh how to do without refresh.



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <asp:Panel ID="Panel1" runat="server">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                        <asp:ListItem>Select</asp:ListItem>
                        <asp:ListItem>Panel2</asp:ListItem>
                    </asp:DropDownList>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="DropDownList1" />                    
                </Triggers>
            </asp:UpdatePanel>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="btnP1" runat="server" Text="Panel1" OnClick="btnP1_Click" />
        </asp:Panel>
        <asp:Panel ID="Panel2" runat="server">
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
                        <asp:ListItem>Select</asp:ListItem>
                        <asp:ListItem>Panel1</asp:ListItem>
                    </asp:DropDownList>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="DropDownList2" />                    
                </Triggers>
            </asp:UpdatePanel>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <asp:Button ID="btnP2" runat="server" Text="Panel2" OnClick="btnP2_Click" />
        </asp:Panel>
    </div>
    </form>
</body>
</html>


protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue.ToString() == "Panel2")
        {
            Panel2.Visible = true;
            Panel1.Visible = false;
        }
    }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList2.SelectedValue.ToString() == "Panel1")
        {
            Panel2.Visible = false;
            Panel1.Visible = true;
        }
    }
    protected void btnP1_Click(object sender, EventArgs e)
    {
        Panel1.Visible = false;
        Panel2.Visible = true;
    }
    protected void btnP2_Click(object sender, EventArgs e)
    {
        Panel1.Visible = true;
        Panel2.Visible = false;
    }
Posted 19-Dec-12 2:50am
Edited 19-Dec-12 2:52am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

hi itsureshuk,

give this :
EventName="SelectedIndexChanged"
in event :
AsyncPostBackTrigger
so, to be this :
<asp:asyncpostbacktrigger controlid="DropDownList1" eventname="SelectedIndexChanged" />

and one again in asp:AsyncPostBackTrigger for DropDownList2

<asp:asyncpostbacktrigger controlid="DropDownList2" eventname="SelectedIndexChanged" />

I hope this helps,
  Permalink  
v2
Comments
itsureshuk 19-Dec-12 8:48am
   
Hi chester_it21 frnd, Thnk u for ur rply.I got output.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 19 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100