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

Discussion in 'ASP .Net' started by Guest, Nov 8, 2005.

  1. Guest

    Guest Guest

    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
    Guest, Nov 8, 2005
    #1
    1. Advertising

  2. Guest

    Mr Newbie Guest

    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('Hello World')");

    }
    }
    }

    }


    --
    Best Regards

    The Inimitable Mr Newbie º¿º
    <> wrote in message
    news:...
    >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
    >
    >
    Mr Newbie, Nov 8, 2005
    #2
    1. Advertising

  3. 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" <>
    | References: <>
    | 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: <>
    | 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!TK2MSFTNGP10.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('Hello World')");
    |
    | }
    | }
    | }
    |
    | }
    |
    |
    | --
    | Best Regards
    |
    | The Inimitable Mr Newbie º¿?
    <> wrote in message
    | news:...
    | >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
    | >
    | >
    |
    |
    |
    Steven Cheng[MSFT], Nov 8, 2005
    #3
  4. Guest

    Guest Guest

    Thanks to everyone. This is the right approach (and I should have remembered
    it! :)

    -KF

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > 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" <>
    > | References: <>
    > | 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: <>
    > | 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!TK2MSFTNGP10.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('Hello World')");
    > |
    > | }
    > | }
    > | }
    > |
    > | }
    > |
    > |
    > | --
    > | Best Regards
    > |
    > | The Inimitable Mr Newbie º¿?
    > <> wrote in message
    > | news:...
    > | >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
    > | >
    > | >
    > |
    > |
    > |
    >
    Guest, Nov 8, 2005
    #4
  5. 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: "" <>
    | From: <>
    | References: <>
    <>
    <>
    | 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: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | NNTP-Posting-Host: idea.urel.washington.edu 128.95.9.12
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.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]" <> wrote in message
    | news:...
    | > 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" <>
    | > | References: <>
    | > | 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: <>
    | > | 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!TK2MSFTNGP10.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('Hello World')");
    | > |
    | > | }
    | > | }
    | > | }
    | > |
    | > | }
    | > |
    | > |
    | > | --
    | > | Best Regards
    | > |
    | > | The Inimitable Mr Newbie º¿?
    | > <> wrote in message
    | > | news:...
    | > | >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
    | > | >
    | > | >
    | > |
    | > |
    | > |
    | >
    |
    |
    |
    Steven Cheng[MSFT], Nov 9, 2005
    #5
    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. Kiki
    Replies:
    2
    Views:
    531
    kiki christie
    Jul 13, 2004
  2. Gnarlodious
    Replies:
    4
    Views:
    17,559
    elizas
    May 5, 2010
  3. Ken Fine
    Replies:
    2
    Views:
    13,091
    Ken Fine
    Sep 25, 2006
  4. ~~~ .NET Ed ~~~
    Replies:
    5
    Views:
    1,344
    David Wainwright
    Mar 27, 2007
  5. cmgmyr

    Add new text box after entered text

    cmgmyr, May 25, 2008, in forum: Javascript
    Replies:
    1
    Views:
    111
    cmgmyr
    May 27, 2008
Loading...

Share This Page