I would like to add Javascript code to be fired when the selected index is changed on a dropdownlist in asp.net.
So, here is my DDL:
<asp:DropDownList ID="comboReportTypes" runat="server" />
I would like to add something like this to the above DDL: onSelectionIndexChanged="MyJavascriptFuntion(this)"
So I'd like to end up with something like this:
<asp:DropDownList ID="comboReportTypes" runat="server" onSelectionIndexChanged="MyJavascriptFuntion(this)" />
Is this possible?
Thanks in advance. I'm using ASP.Net 4.0
add onchange event to it from the code .
Eg: DropDownList dlOption = new DropDownList(); dlOption.Attributes.Add("onchange", "javascript:return functionname(this);");
Using jquery
you can easily achieve what you are trying to do
$('#comboReportTypes').change(function(){
//do whatever you need to.
});
Note: Make sure you are using the correct ID
for the DropDownList
as server
controls tend to change their ID's
on rendering.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.