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

G

Guest

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
 
M

Mr Newbie

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('Hello World')");

}
}
}

}
 
S

Steven Cheng[MSFT]

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" <[email protected]>
| References: <[email protected]>
| 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: <[email protected]>
| 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!TK2MSFTNGP10.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('Hello World')");
|
| }
| }
| }
|
| }
|
|
| --
| Best Regards
|
| The Inimitable Mr Newbie º¿?
| | >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
| >
| >
|
|
|
 
G

Guest

Thanks to everyone. This is the right approach (and I should have remembered
it! :)

-KF
 
S

Steven Cheng[MSFT]

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: "(e-mail address removed)" <[email protected]>
| From: <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
| 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: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: idea.urel.washington.edu 128.95.9.12
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.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
|
| | > 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" <[email protected]>
| > | References: <[email protected]>
| > | 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: <[email protected]>
| > | 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!TK2MSFTNGP10.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('Hello World')");
| > |
| > | }
| > | }
| > | }
| > |
| > | }
| > |
| > |
| > | --
| > | Best Regards
| > |
| > | The Inimitable Mr Newbie º¿?
| > | | > | >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
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top