By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

How can I add a client-side event to an asp:CheckBox ?

P: n/a
Here is the control:

<asp:CheckBox ID="chkLite" runat="server" Checked="False"
AutoPostBack="True" OnCheckedChanged="chkLite_CheckedChanged" />

Here is the code-behind:

chkLite.Attributes.Add("onblur", "LiteChange(this);");

Here is the control as asp.net renders it in the html:

<span onblur="LiteChange(this);"><input id="_ctl0_cph_chkLite"
type="checkbox" name="_ctl0:cph:chkLite" checked="checked"
onclick="javascript:setTimeout('__doPostBack(\'_ct l0$cph$chkLite\',\'\')
', 0)" language="javascript" /></span>

The problem with this is that the onblur event is not fired because the
parent span does not notice when chkLite is checked or unchecked. The
javascript LiteChange() function never fires.

Is there a way I can get this (below) in my html:

<input id="_ctl0_cph_chkLite" type="checkbox" name="_ctl0:cph:chkLite"
checked="checked"
onclick="javascript:setTimeout('__doPostBack(\'_ct l0$cph$chkLite\',\'\')
', 0)" onblur="LiteChange(this);" language="javascript" />

In other words, attach the onblur event directly to the checkbox?

The javascript is below (it's just there as a demonstration, currently
functionally inactive, as you can see).

function LiteChange(oSpan)
{
if(oSpan.children[0].checked)
alert('chkLite is checked');
else
alert('chkLite not checked');
alert('hello');
}
Jan 2 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Instead of asp:CheckBox use <input type="checkbox" runat="server" ... />.
Set all client events in their natural way. Set
onserverchange="chkLite_CheckedChanged".

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"mark4asp" <ma******@gmail.comwrote in message
news:01**********************@news.astraweb.com...
Here is the control:

<asp:CheckBox ID="chkLite" runat="server" Checked="False"
AutoPostBack="True" OnCheckedChanged="chkLite_CheckedChanged" />

Here is the code-behind:

chkLite.Attributes.Add("onblur", "LiteChange(this);");

Here is the control as asp.net renders it in the html:

<span onblur="LiteChange(this);"><input id="_ctl0_cph_chkLite"
type="checkbox" name="_ctl0:cph:chkLite" checked="checked"
onclick="javascript:setTimeout('__doPostBack(\'_ct l0$cph$chkLite\',\'\')
', 0)" language="javascript" /></span>

The problem with this is that the onblur event is not fired because the
parent span does not notice when chkLite is checked or unchecked. The
javascript LiteChange() function never fires.

Is there a way I can get this (below) in my html:

<input id="_ctl0_cph_chkLite" type="checkbox" name="_ctl0:cph:chkLite"
checked="checked"
onclick="javascript:setTimeout('__doPostBack(\'_ct l0$cph$chkLite\',\'\')
', 0)" onblur="LiteChange(this);" language="javascript" />

In other words, attach the onblur event directly to the checkbox?

The javascript is below (it's just there as a demonstration, currently
functionally inactive, as you can see).

function LiteChange(oSpan)
{
if(oSpan.children[0].checked)
alert('chkLite is checked');
else
alert('chkLite not checked');
alert('hello');
}

Jan 2 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.