473,397 Members | 2,028 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,397 software developers and data experts.

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

Similar topics

1
by: Stephen | last post by:
I have a really annoying problem with a datagrid. I have an application which populates a datagrid on the onclick event of a button. The datagrid is bound to an ArrayList which holds the values. ...
3
by: Christopher H. Laco | last post by:
First, a little background. I'm trying to forge ahead into ASP.NET 2.0. I've dome many assemblies in C#, but I've yet to have to use ASP.NET. I'm trying to forge ahead in getting some web/server...
5
by: Nim | last post by:
HI, I would like to know if it's possible inject a dll (create with c++) into an application with c# like c++, and which instruction use c# for do this
1
by: Steven | last post by:
H I'm struggling to think this one through At run time I want to be able to read a layout HTML file from a database which includes tags for modules, e.g ...
3
by: Angel | last post by:
Hi, I have a page which shows a matrix of names and grades for given period. All the grades fields must be editable and they can be up to 200 fields (20 students with 10 grades each) Since...
5
by: dw | last post by:
hello - first, let me state that i am an Asp.Net rookie. here is the situation: i have a page that looks good in the vs.net designer, but when the page renders there are extra amounts...
3
by: inanis | last post by:
Salutations! I have an odd situation and know nothing about regular expressions, but I believe I will need to use them to attempt what I have to do. I am running a script in PHP 5 that takes...
1
by: =?Utf-8?B?SkhpbGJDUk0=?= | last post by:
I am trying to write a httpmodule to inject javascript includes on some of the aspx pages we have. For instance, I want to inject into the resulting IIS response something like... ...
5
by: jeffos101 | last post by:
Hi, I am trying to do the following and would like to know if it's possible using Javascript/Ajax/and some DB I have an Iframe hosted on one server that loads a page which is located on another...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.