473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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

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
1 9734
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dominique Javet | last post by:
Hello, I've a question regarding the checkbox. I've a formular with a list of clients per work experience. I can have several clients for a experience. So I have a table for "experience", one...
12
by: zig | last post by:
I've posted this on alt.comp.lang.coldfusion, but is predominantly a javascript problem: I have a CF query which returns several rows of records. I wanted to have a checkbox on each record of...
7
by: Don | last post by:
Via JavaScript within the client page containing the checkbox, I'm trying to capture the value of a checkbox to make a cookie out of it. But, all I get is the defined "ON" value, even when it is...
4
by: RodBillett | last post by:
I have a situation where I have 3 checkboxes - and at least 1 needs to be selected at all times... I have implemented the code that allows this behavior to happen, BUT Viewstate gets all messed...
4
by: rs | last post by:
how I the client tell the server that the socket is closed? or this there an even that informs the server that the clients socket is close? Oh, I am using vb.net 2003 Thanks
29
by: Amer Neely | last post by:
I've got a dynamically built form with checkboxes for each element ( a list of file names in a directory). I need to grab only those checkboxes that are checked, so I can then delete those files. ...
7
by: sara | last post by:
I have a form where the user is entering information from a phone call. While usually the caller is calling about another person (who will be/is the client), very occasionally, a caller is the...
4
by: narsibvl | last post by:
Here is a piece of html code <form name="package_information" id="package_information" method="post" enctype="multipart/form-data""& lt;" <tr> <td><input type="checkbox"...
2
by: dnaumowicz | last post by:
Hi, I have a page done in ASP .NET 2.0 that uses an asp:CheckBox. .Net renders the CheckBoxin the following manner: <input id="_ctl0_Body__players__ctl0__player" type="checkbox"...
1
by: pavankumar106 | last post by:
hi i need to update checkbox values to database which is in formview control depending upon wat the user selects? i ve written the code lik dis but here its updating depending upon the first...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.