469,267 Members | 998 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

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 4836
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Michael Foord | last post: by
6 posts views Thread by martin | last post: by
5 posts views Thread by c676228 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.