adding a javascript attribute to all text form elements on an asp.net page

Discussion in 'ASP .Net' started by Ken Fine, Sep 25, 2006.

  1. Ken Fine

    Ken Fine Guest

    In code, I'm adding javascript attributes to form elements on an ASP.NET
    page:

    body.Attributes.Add("onClick", "highlight(event);");
    body.Attributes.Add("onKeyUp", "highlight(event);");
    title.Attributes.Add("onClick", "highlight(event);");
    title.Attributes.Add("onKeyUp", "highlight(event);");
    description.Attributes.Add("onKeyUp", "highlight(event);");
    description.Attributes.Add("onClick", "highlight(event);");

    I would like to know how to tell the renderer to generically apply the
    onClick and onKeyUp attributes to all form elements that take text, rather
    than naming those form elements in code, as I do here. The functional
    equivalent of :

    *.Attributes.Add("onClick", "highlight(event);");

    Thanks,
    -KF
    Ken Fine, Sep 25, 2006
    #1
    1. Advertising

  2. What about drilling down Controls collection starting from your page object
    and adding the attributes depending on the control type? You can do it in
    the PreRender event.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    "Ken Fine" <> wrote in message
    news:ef7kpg$nb3$...
    > In code, I'm adding javascript attributes to form elements on an ASP.NET
    > page:
    >
    > body.Attributes.Add("onClick", "highlight(event);");
    > body.Attributes.Add("onKeyUp", "highlight(event);");
    > title.Attributes.Add("onClick", "highlight(event);");
    > title.Attributes.Add("onKeyUp", "highlight(event);");
    > description.Attributes.Add("onKeyUp", "highlight(event);");
    > description.Attributes.Add("onClick", "highlight(event);");
    >
    > I would like to know how to tell the renderer to generically apply the
    > onClick and onKeyUp attributes to all form elements that take text, rather
    > than naming those form elements in code, as I do here. The functional
    > equivalent of :
    >
    > *.Attributes.Add("onClick", "highlight(event);");
    >
    > Thanks,
    > -KF
    >
    Eliyahu Goldin, Sep 25, 2006
    #2
    1. Advertising

  3. Ken Fine

    Ken Fine Guest

    Can someone pass along an analogous snip of code?

    Thank you.

    -KF

    "Eliyahu Goldin" <> wrote in
    message news:...
    > What about drilling down Controls collection starting from your page
    > object and adding the attributes depending on the control type? You can do
    > it in the PreRender event.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    >
    >
    > "Ken Fine" <> wrote in message
    > news:ef7kpg$nb3$...
    >> In code, I'm adding javascript attributes to form elements on an ASP.NET
    >> page:
    >>
    >> body.Attributes.Add("onClick", "highlight(event);");
    >> body.Attributes.Add("onKeyUp", "highlight(event);");
    >> title.Attributes.Add("onClick", "highlight(event);");
    >> title.Attributes.Add("onKeyUp", "highlight(event);");
    >> description.Attributes.Add("onKeyUp", "highlight(event);");
    >> description.Attributes.Add("onClick", "highlight(event);");
    >>
    >> I would like to know how to tell the renderer to generically apply the
    >> onClick and onKeyUp attributes to all form elements that take text,
    >> rather than naming those form elements in code, as I do here. The
    >> functional equivalent of :
    >>
    >> *.Attributes.Add("onClick", "highlight(event);");
    >>
    >> Thanks,
    >> -KF
    >>

    >
    >
    Ken Fine, Sep 25, 2006
    #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. Guest
    Replies:
    4
    Views:
    7,159
    Steven Cheng[MSFT]
    Nov 9, 2005
  2. Replies:
    2
    Views:
    1,076
    Henry S. Thompson
    Mar 6, 2006
  3. domas

    javascript: adding form elements

    domas, Dec 14, 2005, in forum: Javascript
    Replies:
    4
    Views:
    134
    Thomas 'PointedEars' Lahn
    Dec 14, 2005
  4. Replies:
    1
    Views:
    116
  5. Replies:
    4
    Views:
    185
Loading...

Share This Page