Select control with AutoPostBack = true and OnSelectedIndexChanged?

0

I have some html controls that use runat="server" on the server side. The problem is that with the "Select" element when selecting an element I must execute code on the server to load data into other "Select" but I do not accept the AutopostBack="true" or OnSelectedIndexChanged

<select id="mySelect" name="mySelect" runat="server" AutoPostBack="true"  OnSeletedIndexChanged="mySelect_SelectIndexChanged"></select>
    
asked by Popularfan 15.11.2018 в 18:01
source

2 answers

1

Instead of using 'OnSele c tedIndexChanged' (you have a typo there) you can try using the 'onchange' client event:

<select id="mySelect" ... onchange="selectChanged()">

and in your JavaScript:

function selectChanged() {
     var myValue= document.getElementById("mySelect").value;
     __doPostBack('mySelect', myValue);
 }

After this, the postback of the page will be called, which you can use to collect the information sent (myValue) in the code behind using the Request.Params property.

    
answered by 20.11.2018 / 08:18
source
0

Use asp: DropDownList which, like the Select, serves to select a single item from a list.

<asp:DropDownList id="AutosList" AutoPostBack="True" OnSelectedIndexChanged="AutosList_SelectIndexChanged"
                    runat="server">
      <asp:ListItem Value="1">Ford</asp:ListItem>
      <asp:ListItem Value="2">Toyota</asp:ListItem>
      <asp:ListItem Value="3">Ferrari</asp:ListItem>
 </asp:DropDownList>
    
answered by 18.11.2018 в 07:39