Environment: .NET 2.0, visual studio 2005
in aspx markup, set a control like:
<asp:CheckBox ID="E287" runat="server" />
in code behind, hook up event to a javascript func in Page_Load event like:
Me.E287.Attributes.Add("OnCheckedChanged", "javascript:alert(123);")
then test the page in browser, and click on the checkbox, no response. check the source, it is:
<span OnCheckedChanged="javascript:alert();"><input id="E287" type="checkbox" name="E287" /></span>
can’t understand.
If change aspx markup like:
<asp:CheckBox ID="E287" runat="server" OnCheckedChanged="javascript:alert(123);" />
will get error
BC30456: ‘javascript’ is not a member of ‘ASP.MyPage_aspx’.
Really confused. How to resolve this problem?
As you see the rendered control the javascript go to the span (label), to add it to the input/check box you need to use the InputAttributes. Also on the client side you need to use the
onchangeor theonclickto get the results you looking for.so it will be
Thats because the check box use 2 controls to render, one span and one input, so with your code you add on the text the script and not on check box.
There also the LabelAttributes. Here the Attributes are go to the span, because span is parent of input.