why can't i use the attribute "onchange" or "onfocus" in checkbox

when i use the code like this:myCheckBox.Attributes["onfocus"]="this.blur()"

it doesn't work,just generate the tag "span" containing the javascript
MSN:supNate2000@hotmail.com
0
supNate
5/25/2004 5:42:09 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

6 Replies
727 Views

Similar Articles

[PageSpeed] 15

You should be using RegisterStartupScript or RegisterClientScript.  See this article by Scott Mitchell:

Injecting Client-Side Script from an ASP.NET Server Control
http://msdn.microsoft.com/asp.net/using/understanding/aspnet/default.aspx?pull=/library/en-us/dnaspp/html/aspnet-injectclientsidesc.asp
Darrell Norton, MVP
Darrell Norton's Blog


Please mark this post as answered if it helped you!
0
DarrellNorton
5/25/2004 6:34:04 PM
but when i use the code:checkbox.attributes['onclick']="alert('test')";

it works well,why?
MSN:supNate2000@hotmail.com
0
supNate
5/26/2004 3:57:13 AM
> myCheckBox.Attributes["onfocus"]="this.blur()" 

What are you trying to achieve here? What behaviour are you expecting?

Alister
0
SomeNewKid
5/26/2004 9:54:04 AM
hi,SomeNewKid2

if you use the following codes,
<input type="checkbox" onfocus="onblur()">
you will find when you click the checkbox there is no broken line rectangle around the checkbox,so that the page looks more beautiful:)
but i can't do this in asp.net while it was easily solved in asp early versions
MSN:supNate2000@hotmail.com
0
supNate
5/27/2004 7:27:32 AM
I know what you mean about the "focus" rectangle being ugly.

When testing some checkboxes, I only noticed this rectangle when tabbing through the controls ... clicking on a checkbox or its label would not show this rectangle. Is this what you're trying to stop ... the rectangle appearing when the Tab key is used?
If so, I wouldn't recommend removing it ... as it is important visual feedback for people not using a mouse to work with the page.
You can indeed stop this behaviour (as you noted, it is easy in ASP). However, in ASP.NET it doesn't appear you can set onfocus="this.blur()" on an ASP.NET checkbox control, due simply to the way it is rendered. If you *must* have this onfocus attribute, then I think you'll need to create your own checkbox controls, rather than using the corresponding ASP.NET server control.

Alister
0
SomeNewKid
5/29/2004 4:37:58 AM
thank you ,SomeNewKid2,i didn't think about the users with keyboard:(

it seems i shouldn't use this skill:P
MSN:supNate2000@hotmail.com
0
supNate
5/31/2004 2:52:06 PM
Reply: