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

Discussion in 'ASP .Net' started by Guest, Sep 15, 2005.

  1. Guest

    Guest 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
     
    Guest, Sep 15, 2005
    #1
    1. Advertising

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


    <> wrote in message
    news:uX$...
    > 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
    >
     
    Peter Rilling, Sep 16, 2005
    #2
    1. Advertising

  3. 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" <>
    | References: <uX$>
    | 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: <#>
    | 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.
    |
    |
    | <> wrote in message
    | news:uX$...
    | > 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
    | >
    |
    |
    |
     
    Steven Cheng[MSFT], Sep 16, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brent Burkart
    Replies:
    5
    Views:
    823
    Jerry III
    Oct 16, 2003
  2. Alan Silver
    Replies:
    9
    Views:
    2,354
    Alan Silver
    Jun 26, 2005
  3. Replies:
    7
    Views:
    477
    Simon Brooke
    Nov 25, 2006
  4. gervaz
    Replies:
    8
    Views:
    1,100
    Jorgen Grahn
    Jun 26, 2010
  5. Replies:
    3
    Views:
    389
Loading...

Share This Page