1
Reply

Can't get value for DropDownList

Jude Lobo

Jude Lobo

Dec 17 2017 1:59 AM
206
I'm trying to get value of DropDownList in the OnPreInit event, here's the code for it:
 
       protected override void OnPreInit(EventArgs e)
       {
       if(Request.Form["DropDownList1"]!=null)
       {
       var theme = Request.Form["DropDownList1"];
       Page.Theme = theme;
       }
       base.OnPreInit(e);
       }
 But on debugging it returns null every time, here's the code for the dropdownlist:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
      <div class="about-content" style="height:600px">
      <div>
      <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
      <asp:ListItem>Theme1</asp:ListItem>
      <asp:ListItem>Theme2</asp:ListItem>
      </asp:DropDownList>
      </div>
      </asp:Content> 
 
 Also I'm doing this inside a masterpages contentplaceholder, if that helps.
 

Answers (1)