Reputation: 8225
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
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
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.
Upvotes: 0
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