Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > basic: asp.net user controls: how to programmatically add attribute to all text box controls?

Reply
Thread Tools

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

 
 
Guest
Posts: n/a
 
      11-08-2005
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


 
Reply With Quote
 
 
 
 
Mr Newbie
Guest
Posts: n/a
 
      11-08-2005
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
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>
>



 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      11-08-2005
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" <(E-Mail Removed)>
| References: <(E-Mail Removed)>
| 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: <(E-Mail Removed)>
| 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 ?
<(E-Mail Removed)> wrote in message
| news:(E-Mail Removed)...
| >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
| >
| >
|
|
|

 
Reply With Quote
 
Guest
Posts: n/a
 
      11-08-2005
Thanks to everyone. This is the right approach (and I should have remembered
it!

-KF

"Steven Cheng[MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)>
> | References: <(E-Mail Removed)>
> | 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: <(E-Mail Removed)>
> | 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 ?
> <(E-Mail Removed)> wrote in message
> | news:(E-Mail Removed)...
> | >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
> | >
> | >
> |
> |
> |
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      11-09-2005
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 Removed)" <(E-Mail Removed)>
| From: <(E-Mail Removed)>
| References: <(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
| 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: <(E-Mail Removed)>
| 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]" <(E-Mail Removed)> wrote in message
| news:(E-Mail Removed)...
| > 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" <(E-Mail Removed)>
| > | References: <(E-Mail Removed)>
| > | 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: <(E-Mail Removed)>
| > | 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 ?
| > <(E-Mail Removed)> wrote in message
| > | news:(E-Mail Removed)...
| > | >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
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
div box questions; float text around a box, fit box to image size Gnarlodious HTML 4 05-05-2010 11:30 AM
Add new text box after entered text cmgmyr Javascript 1 05-27-2008 04:44 PM
search box & add url box script seamamel@yahoo.fr Java 1 02-06-2007 04:59 AM
Programmatically setting the action attribute of the form tag Nathan Sokalski ASP .Net 0 02-02-2007 06:26 AM
Add user controls to programmatically specified location Kiki ASP .Net 2 07-13-2004 09:14 PM



Advertisments