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

G

Guest

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
 
P

Peter Rilling

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.
 
S

Steven Cheng[MSFT]

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" <[email protected]>
| References: <[email protected]>
| 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: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 70.97.58.2
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.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.
|
|
| | > 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
| >
|
|
|
 

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

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top