Laziale
Laziale

Reputation: 8225

html select (dropdown) control selected index changed event in asp.net

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

Upvotes: 3

Views: 38713

Answers (3)

The Vanilla Thrilla
The Vanilla Thrilla

Reputation: 2005

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"

Upvotes: 5

Shyju
Shyju

Reputation: 218852

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

Upvotes: 0

nikeaa
nikeaa

Reputation: 1047

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" />

Upvotes: 3

Related Questions