473,748 Members | 8,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="hiligh tActiveElement( this);

So the whole control looks like:
<asp:TextBox ID="TextBox_Pat ientAddress2" runat="server" TabIndex="6"
Width="223px" onfocus="hiligh tActiveElement( 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.s tyle.background = ''";
onblur="this.st yle.background = '';"

Any ideas welcome. Thanks!
Steve
Sep 17 '06 #1
1 1473
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******** ******@TK2MSFTN GP02.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="hiligh tActiveElement( this);

So the whole control looks like:
<asp:TextBox ID="TextBox_Pat ientAddress2" runat="server" TabIndex="6"
Width="223px" onfocus="hiligh tActiveElement( 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.s tyle.background = ''";
onblur="this.st yle.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
1737
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. Everything worked perfectly for me in my test application however when I copied and pasted the code accross to my main project something strange started to happen. On the on-click event of the button (cmdExcAdrContinue) the datagrid is populated...
3
1741
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 controls created so during a future conversion the work is already done for other programmers. I've started created common controls used in various ecommerce checkouts. For example, credit card validation, promo vcodes validation, etc. Some sites...
5
6204
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
1522
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 <HTML><BODY><table><tr><td><ModuleTag>1</ModuleTag></td><td><ModuleTag>2</ModuleTag></td></tr></table></BODY></HTML I would then like to, at run time, interpret the module tags and replace them with custom web controls (e.g., Announcement, Article). The reason for doing this at run...
3
12876
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 there are a lots of fields I do not want to go back and forth to validate entered values on any change. I decided that this may be achieved with some JavaScript functions to validate some controls and to calculate average and total values of other...
5
1932
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 (vertically) of space between controls. i have all of the controls in a table, to help line them up, and I have reviewed the html to verify that there are no extra spaces or paragraphs or breaks between the controls. however, when i run the web site,...
3
2140
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 some user input, formats and sends that input to a completely different server and puts that server's reply -- basically the entire returned page -- into a string. I have the entire contents of the resulting HTML page in a string called...
1
3490
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... response.Write("<script language='javascript'>"); response.Write("alert('tt');"); response.Write(@"</script>");
5
5141
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 server. So mydomain.com is in the browser address bar and loads PageA (from Mydomain2.com). Page A contains a form and a submit button. I need to Inject some data from the Db into one or several fields contained in the Form on PageA. And...
0
8831
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.