PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

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

 
 
mark4asp
Guest
Posts: n/a
 
      2nd Jan 2008
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(\'_ctl0$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(\'_ctl0$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');
}
 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      2nd Jan 2008
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" <(E-Mail Removed)> wrote in message
news:017a39b4$0$25652$(E-Mail Removed)...
> 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(\'_ctl0$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(\'_ctl0$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');
> }



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mixing a client-side/server-side event =?Utf-8?B?am9uZWZlcg==?= Microsoft Dot NET 7 5th Jun 2007 10:27 PM
Client Side Checkbox Code Microsoft ASP .NET 4 21st Dec 2005 02:18 PM
Safe to have client-side AND server-side page load event procedures? Fred Microsoft ASP .NET 2 12th Jul 2004 07:46 PM
Button disabled and re-enabled in client side not firing server-side click event. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?= Microsoft ASP .NET 1 2nd Jun 2004 04:44 PM
fire server side event from client side code =?Utf-8?B?TmVpbA==?= Microsoft ASP .NET 5 23rd Mar 2004 11:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:08 PM.