inject extra code into all controls on a page

S

sklett

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
 
C

Cowboy \(Gregory A. Beamer\)

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!
*************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top