472,958 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

basic: asp.net user controls: how to programmatically 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(event);");
body.Attributes.Add("onKeyUp", "highlight(event);");

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 4978
using System;

namespace WebControlLibrary1
{
/// <summary>
/// Summary description for NewTextBox.
/// </summary>
public class NewTextBox : System.Web.UI.WebControls.TextBox
{
public NewTextBox()
{
//
// TODO: Add constructor logic here
//

this.Attributes.Add("onClick","javascript:alert('H ello World')");

}
}
}

}
--
Best Regards

The Inimitable Mr Newbie
<ke*****@nospam.nospam> wrote in message
news:un**************@TK2MSFTNGP12.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(event);");
body.Attributes.Add("onKeyUp", "highlight(event);");

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 programmatically 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.public.dotnet.framework.aspnet
| NNTP-Posting-Host: host81-137-199-51.in-addr.btopenworld.com 81.137.199.51
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:136857
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| using System;
|
| namespace WebControlLibrary1
| {
| /// <summary>
| /// Summary description for NewTextBox.
| /// </summary>
| public class NewTextBox : System.Web.UI.WebControls.TextBox
| {
| public NewTextBox()
| {
| //
| // TODO: Add constructor logic here
| //
|
| this.Attributes.Add("onClick","javascript:alert('H ello World')");
|
| }
| }
| }
|
| }
|
|
| --
| Best Regards
|
| The Inimitable Mr Newbie ?
<ke*****@nospam.nospam> wrote in message
| news:un**************@TK2MSFTNGP12.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(event);");
| > body.Attributes.Add("onKeyUp", "highlight(event);");
| >
| > 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**************@TK2MSFTNGXA01.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 programmatically 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.public.dotnet.framework.aspnet
| NNTP-Posting-Host: host81-137-199-51.in-addr.btopenworld.com
81.137.199.51
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:136857
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| using System;
|
| namespace WebControlLibrary1
| {
| /// <summary>
| /// Summary description for NewTextBox.
| /// </summary>
| public class NewTextBox : System.Web.UI.WebControls.TextBox
| {
| public NewTextBox()
| {
| //
| // TODO: Add constructor logic here
| //
|
| this.Attributes.Add("onClick","javascript:alert('H ello World')");
|
| }
| }
| }
|
| }
|
|
| --
| Best Regards
|
| The Inimitable Mr Newbie ?
<ke*****@nospam.nospam> wrote in message
| news:un**************@TK2MSFTNGP12.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(event);");
| > body.Attributes.Add("onKeyUp", "highlight(event);");
| >
| > 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.washington.edu>
| From: <ke*****@nospam.nospam>
| References: <un**************@TK2MSFTNGP12.phx.gbl>
<Oy**************@TK2MSFTNGP10.phx.gbl>
<wf**************@TK2MSFTNGXA01.phx.gbl>
| Subject: Re: basic: asp.net user controls: how to programmatically 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.public.dotnet.framework.aspnet
| NNTP-Posting-Host: idea.urel.washington.edu 128.95.9.12
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:136961
| X-Tomcat-NG: microsoft.public.dotnet.framework.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**************@TK2MSFTNGXA01.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 programmatically 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.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: host81-137-199-51.in-addr.btopenworld.com
| > 81.137.199.51
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:136857
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | using System;
| > |
| > | namespace WebControlLibrary1
| > | {
| > | /// <summary>
| > | /// Summary description for NewTextBox.
| > | /// </summary>
| > | public class NewTextBox : System.Web.UI.WebControls.TextBox
| > | {
| > | public NewTextBox()
| > | {
| > | //
| > | // TODO: Add constructor logic here
| > | //
| > |
| > | this.Attributes.Add("onClick","javascript:alert('H ello World')");
| > |
| > | }
| > | }
| > | }
| > |
| > | }
| > |
| > |
| > | --
| > | Best Regards
| > |
| > | The Inimitable Mr Newbie ?
| > <ke*****@nospam.nospam> wrote in message
| > | news:un**************@TK2MSFTNGP12.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(event);");
| > | > body.Attributes.Add("onKeyUp", "highlight(event);");
| > | >
| > | > 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
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. #...
1
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...
6
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"...
5
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...
8
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...
9
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...
6
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...
2
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...
6
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...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.