473,765 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

basic: asp.net user controls: how to programmaticall y add attribute to all text box controls?

I have a "form field highlight" javascript that I've added to some of my
ASP.NET forms using the following syntax:

body.Attributes .Add("onClick", "highlight(even t);");
body.Attributes .Add("onKeyUp", "highlight(even t);");

Some of my forms have a great many text box controls that I want to
highlight.. I would much rather that ASP.NET do the work of looping through
all text boxes and applying these two attributes.

Can someone give me the dummies how-to? I'm using C#.

-KF
Nov 19 '05 #1
4 5054
using System;

namespace WebControlLibra ry1
{
/// <summary>
/// Summary description for NewTextBox.
/// </summary>
public class NewTextBox : System.Web.UI.W ebControls.Text Box
{
public NewTextBox()
{
//
// TODO: Add constructor logic here
//

this.Attributes .Add("onClick", "javascript:ale rt('Hello World')");

}
}
}

}
--
Best Regards

The Inimitable Mr Newbie º¿º
<ke*****@nospam .nospam> wrote in message
news:un******** ******@TK2MSFTN GP12.phx.gbl...
I have a "form field highlight" javascript that I've added to some of my
ASP.NET forms using the following syntax:

body.Attributes .Add("onClick", "highlight(even t);");
body.Attributes .Add("onKeyUp", "highlight(even t);");

Some of my forms have a great many text box controls that I want to
highlight.. I would much rather that ASP.NET do the work of looping
through all text boxes and applying these two attributes.

Can someone give me the dummies how-to? I'm using C#.

-KF

Nov 19 '05 #2
Hi KF,

As for your scenario, I think Mr Newbie's sugestion on use a custom derived
TextBox class to replace all the textbox(you'd like to highlight) is the
better apprach. Since the ASP.NET page's control structure may be very
complex, loop all the TextBoxes on a page will cause critical performance
problem, especiall when there any many container controls (such as DataGrid
/ DataList ) which also contains nested textboxes...

So do you think using a custom TextBox class ok? If you have any other
questions, please feel free to post here.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Mr Newbie" <he**@now.com >
| References: <un************ **@TK2MSFTNGP12 .phx.gbl>
| Subject: Re: basic: asp.net user controls: how to programmaticall y add
attribute to all text box controls?
| Date: Tue, 8 Nov 2005 10:02:07 -0000
| Lines: 47
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Response
| Message-ID: <Oy************ **@TK2MSFTNGP10 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: host81-137-199-51.in-addr.btopenworl d.com 81.137.199.51
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1368 57
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| using System;
|
| namespace WebControlLibra ry1
| {
| /// <summary>
| /// Summary description for NewTextBox.
| /// </summary>
| public class NewTextBox : System.Web.UI.W ebControls.Text Box
| {
| public NewTextBox()
| {
| //
| // TODO: Add constructor logic here
| //
|
| this.Attributes .Add("onClick", "javascript:ale rt('Hello World')");
|
| }
| }
| }
|
| }
|
|
| --
| Best Regards
|
| The Inimitable Mr Newbie º¿?
<ke*****@nospam .nospam> wrote in message
| news:un******** ******@TK2MSFTN GP12.phx.gbl...
| >I have a "form field highlight" javascript that I've added to some of my
| >ASP.NET forms using the following syntax:
| >
| > body.Attributes .Add("onClick", "highlight(even t);");
| > body.Attributes .Add("onKeyUp", "highlight(even t);");
| >
| > Some of my forms have a great many text box controls that I want to
| > highlight.. I would much rather that ASP.NET do the work of looping
| > through all text boxes and applying these two attributes.
| >
| > Can someone give me the dummies how-to? I'm using C#.
| >
| > -KF
| >
| >
|
|
|

Nov 19 '05 #3
Thanks to everyone. This is the right approach (and I should have remembered
it! :)

-KF

"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
news:wf******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi KF,

As for your scenario, I think Mr Newbie's sugestion on use a custom
derived
TextBox class to replace all the textbox(you'd like to highlight) is the
better apprach. Since the ASP.NET page's control structure may be very
complex, loop all the TextBoxes on a page will cause critical performance
problem, especiall when there any many container controls (such as
DataGrid
/ DataList ) which also contains nested textboxes...

So do you think using a custom TextBox class ok? If you have any other
questions, please feel free to post here.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Mr Newbie" <he**@now.com >
| References: <un************ **@TK2MSFTNGP12 .phx.gbl>
| Subject: Re: basic: asp.net user controls: how to programmaticall y add
attribute to all text box controls?
| Date: Tue, 8 Nov 2005 10:02:07 -0000
| Lines: 47
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Response
| Message-ID: <Oy************ **@TK2MSFTNGP10 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: host81-137-199-51.in-addr.btopenworl d.com
81.137.199.51
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1368 57
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| using System;
|
| namespace WebControlLibra ry1
| {
| /// <summary>
| /// Summary description for NewTextBox.
| /// </summary>
| public class NewTextBox : System.Web.UI.W ebControls.Text Box
| {
| public NewTextBox()
| {
| //
| // TODO: Add constructor logic here
| //
|
| this.Attributes .Add("onClick", "javascript:ale rt('Hello World')");
|
| }
| }
| }
|
| }
|
|
| --
| Best Regards
|
| The Inimitable Mr Newbie º¿?
<ke*****@nospam .nospam> wrote in message
| news:un******** ******@TK2MSFTN GP12.phx.gbl...
| >I have a "form field highlight" javascript that I've added to some of
my
| >ASP.NET forms using the following syntax:
| >
| > body.Attributes .Add("onClick", "highlight(even t);");
| > body.Attributes .Add("onKeyUp", "highlight(even t);");
| >
| > Some of my forms have a great many text box controls that I want to
| > highlight.. I would much rather that ASP.NET do the work of looping
| > through all text boxes and applying these two attributes.
| >
| > Can someone give me the dummies how-to? I'm using C#.
| >
| > -KF
| >
| >
|
|
|

Nov 19 '05 #4
You're welcome KF,

Feel free to post here when you need any assistance.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Reply-To: "ke*****@nospam .nospam" <ke*****@u.wash ington.edu>
| From: <ke*****@nospam .nospam>
| References: <un************ **@TK2MSFTNGP12 .phx.gbl>
<Oy************ **@TK2MSFTNGP10 .phx.gbl>
<wf************ **@TK2MSFTNGXA0 1.phx.gbl>
| Subject: Re: basic: asp.net user controls: how to programmaticall y add
attribute to all text box controls?
| Date: Tue, 8 Nov 2005 08:01:42 -0800
| Lines: 102
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <ew************ **@TK2MSFTNGP12 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: idea.urel.washi ngton.edu 128.95.9.12
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1369 61
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Thanks to everyone. This is the right approach (and I should have
remembered
| it! :)
|
| -KF
|
| "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| news:wf******** ******@TK2MSFTN GXA01.phx.gbl.. .
| > Hi KF,
| >
| > As for your scenario, I think Mr Newbie's sugestion on use a custom
| > derived
| > TextBox class to replace all the textbox(you'd like to highlight) is the
| > better apprach. Since the ASP.NET page's control structure may be very
| > complex, loop all the TextBoxes on a page will cause critical
performance
| > problem, especiall when there any many container controls (such as
| > DataGrid
| > / DataList ) which also contains nested textboxes...
| >
| > So do you think using a custom TextBox class ok? If you have any other
| > questions, please feel free to post here.
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| > --------------------
| > | From: "Mr Newbie" <he**@now.com >
| > | References: <un************ **@TK2MSFTNGP12 .phx.gbl>
| > | Subject: Re: basic: asp.net user controls: how to programmaticall y add
| > attribute to all text box controls?
| > | Date: Tue, 8 Nov 2005 10:02:07 -0000
| > | Lines: 47
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | X-RFC2646: Format=Flowed; Response
| > | Message-ID: <Oy************ **@TK2MSFTNGP10 .phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| > | NNTP-Posting-Host: host81-137-199-51.in-addr.btopenworl d.com
| > 81.137.199.51
| > | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| > | Xref: TK2MSFTNGXA01.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:1368 57
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > |
| > | using System;
| > |
| > | namespace WebControlLibra ry1
| > | {
| > | /// <summary>
| > | /// Summary description for NewTextBox.
| > | /// </summary>
| > | public class NewTextBox : System.Web.UI.W ebControls.Text Box
| > | {
| > | public NewTextBox()
| > | {
| > | //
| > | // TODO: Add constructor logic here
| > | //
| > |
| > | this.Attributes .Add("onClick", "javascript:ale rt('Hello World')");
| > |
| > | }
| > | }
| > | }
| > |
| > | }
| > |
| > |
| > | --
| > | Best Regards
| > |
| > | The Inimitable Mr Newbie º¿?
| > <ke*****@nospam .nospam> wrote in message
| > | news:un******** ******@TK2MSFTN GP12.phx.gbl...
| > | >I have a "form field highlight" javascript that I've added to some
of
| > my
| > | >ASP.NET forms using the following syntax:
| > | >
| > | > body.Attributes .Add("onClick", "highlight(even t);");
| > | > body.Attributes .Add("onKeyUp", "highlight(even t);");
| > | >
| > | > Some of my forms have a great many text box controls that I want to
| > | > highlight.. I would much rather that ASP.NET do the work of looping
| > | > through all text boxes and applying these two attributes.
| > | >
| > | > Can someone give me the dummies how-to? I'm using C#.
| > | >
| > | > -KF
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
9290
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. # No warranty express or implied for the accuracy, fitness to purpose
1
3024
by: Martine | last post by:
Hi there! I have a problem with programmatically adding user controls to my mobile webforms. If I load my usercontrol programmatically (in the Page_Load), the object is instantiated, I have access to the methods and properties from the Page_Load, no problem there. But as soon as I want access to the user control from another procedure on the same page, I get the next error message: "Object reference not set to an instance of an...
6
11300
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header" Src="WebControls/Header.ascx" %> The web user control contains the following server controls
5
2877
by: c676228 | last post by:
Hi, I guess I am confused. In aspx script, I mean (you won't use Codebehind="enrollinfo.aspx.vb", but mix code with html and code together) You can access user control's property directly. Since I am useing visual studio .net, the html and code are seperated. I have the following aspx code which has two user controls: <%@ Register TagPrefix="Subway" TagName="Peopleinfo" Src="Peopleinfo.ascx" %> <%@ Register TagPrefix="Subway"...
8
2488
by: Andrew | last post by:
Hello, friends, We created a drop-down menu bar and a show/hide calendar web user controls mainly using javaScript and html. However, they both have the problem that they are not dispaly as the top controls in IE browser. Rather, text box, file field, and etc. are on the top. As a result, our calendar and drop-down menu bar were "cut" here and there wherever there is one of those boxes.
9
4103
by: Alan Silver | last post by:
Hello, I have a user control which I am trying to load dynamically, but am running into problems. I think the problem is because I have two .ascx files that refer to the same .ascx.cs file. A simple example is like this... Ferret1.ascx =========
6
11081
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to how those properties are set. I want to be able to do two other things: a) add User control instances to my page, filling in the place of placeholder controls, and b) programmatically setting custom properties on those dynamically spawned...
2
15071
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have been able to find the cause of the problem, and will describe it here first textually and then through a code example. The purpose of what I am trying to do is to create a postback-free web application through the use of ASP.net AJAX UpdatePanels...
6
10123
by: alun65 | last post by:
I'm having trouble programmatically adding a user control and then setting some of it's server controls. I add the user control to the code behind and add it to a placeholder: protected void Page_Load(object sender, EventArgs e) { UserControls_WebUserControl myControl = new UserControls_WebUserControl(); PlaceHolder1.Controls.Add(web);
0
9398
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
10160
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
10007
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...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7378
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
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
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
3
2805
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.