I would like to have a dropdown list in a master page using an update panel so the page does not refresh. I would like the selected value from the dropdown list to be used on a content page of the master page. I created this simple example. When clicking DropDownList1 the label on the content page is updated. When clicking DropDownList2 with the update panel the label does not get updated. This is my first time using an update panel; some help is appreciated.
master aspx
<head runat="server">
<title>Color</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
<asp:ListItem Value="Green">Green</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
<asp:ListItem Value="Orange">Orange</asp:ListItem>
<asp:ListItem Value="Purple">Purple</asp:ListItem>
</asp:DropDownList>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true">
<asp:ListItem Value="Orange">Pink</asp:ListItem>
<asp:ListItem Value="Purple">Red</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList2" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
master code behind
Private Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim color As String = DropDownList1.SelectedValue.ToString
Dim lbl As Label = CType(ContentPlaceHolder1.FindControl("Label1"), Label)
If Not lbl Is Nothing Then
lbl.Text = color
End If
End Sub
Protected Sub DropDownList2_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim color As String = DropDownList2.SelectedValue.ToString
Dim lbl As Label = CType(ContentPlaceHolder1.FindControl("Label1"), Label)
If Not lbl Is Nothing Then
lbl.Text = color
End If
End Sub
content page
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<title>Color_Page1</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</asp:Content>
Thanks, Pat