469,609 Members | 1,455 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

inject extra code into all controls on a page

I want to implement a simple form element focus script that will change the
color of a form element when it gets focus and revert back when it loses
focus.

I've got the code working (simple) but now I need to add it to ALL my form
controls and there are tons. Is there a way to override page rendering and
insert the javascript into the rendered page source?

For example, this is what I would like to add to my controls:
onfocus="hilightActiveElement(this);

So the whole control looks like:
<asp:TextBox ID="TextBox_PatientAddress2" runat="server" TabIndex="6"
Width="223px" onfocus="hilightActiveElement(this);" />

I'm using a function now so that as I tweak the look and feel I don't need
to update it too many places, but if I was going to inject it at render time
I would just use: onfocus="this.style.background = ''";
onblur="this.style.background = '';"

Any ideas welcome. Thanks!
Steve
Sep 17 '06 #1
1 1355
There is no magic way to do it, but I have a couple of directions you can
go.

1. Loop through controls on load. This requires little thought.
2. Create your own controls that inherit from the controls in .NET and have
the bits added you need. This is a bit better as the control automagically
picks up the behavior. You can even have the first control on the page emit
the JavaScript and have others know the script is out there (with a bit more
work).

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
"sklett" <s@s.comwrote in message
news:ul**************@TK2MSFTNGP02.phx.gbl...
>I want to implement a simple form element focus script that will change the
color of a form element when it gets focus and revert back when it loses
focus.

I've got the code working (simple) but now I need to add it to ALL my form
controls and there are tons. Is there a way to override page rendering
and insert the javascript into the rendered page source?

For example, this is what I would like to add to my controls:
onfocus="hilightActiveElement(this);

So the whole control looks like:
<asp:TextBox ID="TextBox_PatientAddress2" runat="server" TabIndex="6"
Width="223px" onfocus="hilightActiveElement(this);" />

I'm using a function now so that as I tweak the look and feel I don't need
to update it too many places, but if I was going to inject it at render
time I would just use: onfocus="this.style.background = ''";
onblur="this.style.background = '';"

Any ideas welcome. Thanks!
Steve

Sep 17 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Christopher H. Laco | last post: by
5 posts views Thread by Nim | last post: by
1 post views Thread by Steven | last post: by
3 posts views Thread by Angel | last post: by
1 post views Thread by =?Utf-8?B?SkhpbGJDUk0=?= | last post: by
reply views Thread by Solution2021 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.