3

I am trying to put backend code to my html select control (dropdown) when the value is changed a backend method to be triggered, but I Can't find the event. I tried this way:

<select id="ddlCompany" name="select2" onchange="ddlCompany_SelectedIndexChanged" runat="server" class="dropdown nostyle sel1" style="width:100%;" placeholder="Select Company" />

nothing changes. Can anyone advice how I can fix this? Thx, Laziale

Laziale
  • 7,965
  • 46
  • 146
  • 262

3 Answers3

5

Add this to your code behind:

protected void ddlCompany_SelectedIndexChanged(object sender, EventArgs e)
{
     //code here
}

And this to your markup:

OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged" AutoPostBack="True"
The Vanilla Thrilla
  • 1,915
  • 10
  • 30
  • 49
3

Try using the SelectedIndexChanged property instead of onchange, like this:

<select id="ddlCompany" name="select2" OnSelectedIndexChanged="ddlCompany_SelectedIndexChanged" runat="server" class="dropdown nostyle sel1" style="width:100%;" placeholder="Select Company" />
nikeaa
  • 1,047
  • 7
  • 17
  • So I tried both your and The Vanilla Thrilla's answers and neither of them worked, this is not an aspx or .net control... how then can it call C# methods? – 5tar-Kaster Nov 08 '13 at 09:30
  • Are you saying that what you are trying to use is not an aspx or .net control? If so, then this answer won't work. – nikeaa Nov 08 '13 at 15:08
  • well there isn't such a thing as OnSelectedIndexChanged in the properties menu in Visual Studio so I assume it isn't a .net or aspx control... I also cannot see any other Select control anywhere – 5tar-Kaster Nov 11 '13 at 07:53
0

If you are using the dropdownlist server control. Go to the designer view, Select the dropdownlist server control and right click and select Properties. Now in the properties window, click on the Events icon and then you can see the SelectedIndexChanged event. Double click on the blank white space on the right side and Visual studio will generate the relevant code for you.

enter image description here

Shyju
  • 214,206
  • 104
  • 411
  • 497