On checkbox changed event (C#)
<%@Page Language="C#" %>
<html>
<head>
<title>Web Form 'Change' and 'Click' Events</title>
</head>
<body>
<span class="heading">Web Form 'Change' and 'Click' Events</span><p />
<form runat="server">
<asp:textbox id="MyText" text="OriginalValue"
ontextchanged="MyChangeCode" runat="server" />
<asp:dropdownlist id="MyListBox"
onselectedindexchanged="MyChangeCode" runat="server">
<asp:listitem text="Option 1" value="Value1" runat="server" />
<asp:listitem text="Option 2" value="Value2" runat="server" />
<asp:listitem text="Option 3" value="Value3" runat="server" />
</asp:dropdownlist>
<asp:checkbox id="MyCheckBox"
oncheckedchanged="MyChangeCode" runat="server" />
<asp:button id="MySubmitButton" text="Submit"
onclick="MyClickCode" runat="server" />
</form>
<div id="divResult" runat="server" enableviewstate="false" /><p />
<div class="cite">Change the values in the controls and click 'Submit'</div>
<script runat="server">
void MyChangeCode(object objSender, EventArgs objArgs) {
Control ctrSender = (Control)objSender;
divResult.InnerHtml += "Change event detected for control '"
+ ctrSender.ID + "'<br />";
}
void MyClickCode(object objSender, EventArgs objArgs) {
Control ctrSender = (Control)objSender;
divResult.InnerHtml += "Click event detected for control '"
+ ctrSender.ID + "'<br />";
}
</script>
</body>
</html>
Related examples in the same category