Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > +Simplest+ way to attributes to all of a particular Web Form control type?

Reply
Thread Tools

+Simplest+ way to attributes to all of a particular Web Form control type?

 
 
Guest
Posts: n/a
 
      09-15-2005
For a given web form, I want to know what the +simplest+ way to add an
attribute to all of a particular control type on that page. For example, I
might want to add an onClick attribute to all TextBoxes on the page, e.g.

[TextBoxName].Attributes.Add("onKeyUp", "dosomething(event);");

I know that I can create a custom user control or custom control or
otherwise extend stuff with some work. I'm wondering if there's a quicker
and dirtier way to do this on a per-page basis.

Thanks.

-KF


 
Reply With Quote
 
 
 
 
Peter Rilling
Guest
Posts: n/a
 
      09-15-2005
Well, you mentioned that you could extend a particular type. In that you
could write the attribute out, so instead of using TextBox, you might use
your custom control MyTextBox that inherits from TextBox.

You could also in the PreRender event, for instance, cycle through all the
controls on the page using what is in the Controls collection. Then you can
check their type and output the attributes accordingly.


<(E-Mail Removed)> wrote in message
news:uX$(E-Mail Removed)...
> For a given web form, I want to know what the +simplest+ way to add an
> attribute to all of a particular control type on that page. For example, I
> might want to add an onClick attribute to all TextBoxes on the page, e.g.
>
> [TextBoxName].Attributes.Add("onKeyUp", "dosomething(event);");
>
> I know that I can create a custom user control or custom control or
> otherwise extend stuff with some work. I'm wondering if there's a quicker
> and dirtier way to do this on a per-page basis.
>
> Thanks.
>
> -KF
>



 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      09-16-2005
Thanks for Peter's inputs.

Hi Kenfine,

As for your scenario, I think using a custom Control will be a prefered
approach since dynamically loop through the Page's Controls collection and
sub control's collection recursively will be very expensive. Also, if you
just loop through the top level control(which underneath the HtmlForm ) ,
that's OK. If some of those controls are nested in other controls or in
very deep hierarchy, I think use Custom Control to centralize the operation
will be more reasonable. Thanks,

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: "Peter Rilling" <(E-Mail Removed)>
| References: <uX$(E-Mail Removed)>
| Subject: Re: +Simplest+ way to attributes to all of a particular Web Form
control type?
| Date: Thu, 15 Sep 2005 16:40:40 -0700
| Lines: 27
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
| Message-ID: <#(E-Mail Removed)>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 70.97.58.2
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:125002
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Well, you mentioned that you could extend a particular type. In that you
| could write the attribute out, so instead of using TextBox, you might use
| your custom control MyTextBox that inherits from TextBox.
|
| You could also in the PreRender event, for instance, cycle through all
the
| controls on the page using what is in the Controls collection. Then you
can
| check their type and output the attributes accordingly.
|
|
| <(E-Mail Removed)> wrote in message
| news:uX$(E-Mail Removed)...
| > For a given web form, I want to know what the +simplest+ way to add an
| > attribute to all of a particular control type on that page. For
example, I
| > might want to add an onClick attribute to all TextBoxes on the page,
e.g.
| >
| > [TextBoxName].Attributes.Add("onKeyUp", "dosomething(event);");
| >
| > I know that I can create a custom user control or custom control or
| > otherwise extend stuff with some work. I'm wondering if there's a
quicker
| > and dirtier way to do this on a per-page basis.
| >
| > Thanks.
| >
| > -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
Is there a way to bind a particular IP address for outbound reques ralderton ASP .Net 0 05-10-2009 04:43 AM
ASP/ASP.NET page that reacts a special way to items coming from a particular subdomain (programmatically testing subdomain?) Ken Fine ASP .Net 3 02-29-2008 05:35 AM
How to not cache a particular web form? =?Utf-8?B?Q2hyeXNhbg==?= ASP .Net 2 09-29-2005 04:03 AM
What's the best way to hide the particular STL container that my class uses? Ed C++ 3 04-04-2005 01:17 PM



Advertisments