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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

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

    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(even t);");
    body.Attributes .Add("onKeyUp", "highlight(even t);");

    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

    #2
    Re: basic: asp.net user controls: how to programmaticall y add attribute to all text box controls?

    using System;

    namespace WebControlLibra ry1
    {
    /// <summary>
    /// Summary description for NewTextBox.
    /// </summary>
    public class NewTextBox : System.Web.UI.W ebControls.Text Box
    {
    public NewTextBox()
    {
    //
    // TODO: Add constructor logic here
    //

    this.Attributes .Add("onClick", "javascript:ale rt('Hello World')");

    }
    }
    }

    }


    --
    Best Regards

    The Inimitable Mr Newbie º¿º
    <kenfine@nospam .nospam> wrote in message
    news:un5vTzD5FH A.2364@TK2MSFTN GP12.phx.gbl...[color=blue]
    >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(even t);");
    > body.Attributes .Add("onKeyUp", "highlight(even t);");
    >
    > 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
    >
    >[/color]


    Comment

    • Steven Cheng[MSFT]

      #3
      Re: basic: asp.net user controls: how to programmaticall y add attribute to all text box controls?

      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" <here@now.com >
      | References: <un5vTzD5FHA.23 64@TK2MSFTNGP12 .phx.gbl>
      | Subject: Re: basic: asp.net user controls: how to programmaticall y 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: <Oy4u3tE5FHA.12 52@TK2MSFTNGP10 .phx.gbl>
      | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
      | NNTP-Posting-Host: host81-137-199-51.in-addr.btopenworl d.com 81.137.199.51
      | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
      | Xref: TK2MSFTNGXA01.p hx.gbl
      microsoft.publi c.dotnet.framew ork.aspnet:1368 57
      | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
      |
      | using System;
      |
      | namespace WebControlLibra ry1
      | {
      | /// <summary>
      | /// Summary description for NewTextBox.
      | /// </summary>
      | public class NewTextBox : System.Web.UI.W ebControls.Text Box
      | {
      | public NewTextBox()
      | {
      | //
      | // TODO: Add constructor logic here
      | //
      |
      | this.Attributes .Add("onClick", "javascript:ale rt('Hello World')");
      |
      | }
      | }
      | }
      |
      | }
      |
      |
      | --
      | Best Regards
      |
      | The Inimitable Mr Newbie º¿?
      <kenfine@nospam .nospam> wrote in message
      | news:un5vTzD5FH A.2364@TK2MSFTN GP12.phx.gbl...
      | >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(even t);");
      | > body.Attributes .Add("onKeyUp", "highlight(even t);");
      | >
      | > 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
      | >
      | >
      |
      |
      |

      Comment

      • Guest's Avatar

        #4
        Re: basic: asp.net user controls: how to programmaticall y add attribute to all text box controls?

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

        -KF

        "Steven Cheng[MSFT]" <stcheng@online .microsoft.com> wrote in message
        news:wf1l8NF5FH A.2880@TK2MSFTN GXA01.phx.gbl.. .[color=blue]
        > 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" <here@now.com >
        > | References: <un5vTzD5FHA.23 64@TK2MSFTNGP12 .phx.gbl>
        > | Subject: Re: basic: asp.net user controls: how to programmaticall y 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: <Oy4u3tE5FHA.12 52@TK2MSFTNGP10 .phx.gbl>
        > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
        > | NNTP-Posting-Host: host81-137-199-51.in-addr.btopenworl d.com
        > 81.137.199.51
        > | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
        > | Xref: TK2MSFTNGXA01.p hx.gbl
        > microsoft.publi c.dotnet.framew ork.aspnet:1368 57
        > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
        > |
        > | using System;
        > |
        > | namespace WebControlLibra ry1
        > | {
        > | /// <summary>
        > | /// Summary description for NewTextBox.
        > | /// </summary>
        > | public class NewTextBox : System.Web.UI.W ebControls.Text Box
        > | {
        > | public NewTextBox()
        > | {
        > | //
        > | // TODO: Add constructor logic here
        > | //
        > |
        > | this.Attributes .Add("onClick", "javascript:ale rt('Hello World')");
        > |
        > | }
        > | }
        > | }
        > |
        > | }
        > |
        > |
        > | --
        > | Best Regards
        > |
        > | The Inimitable Mr Newbie º¿?
        > <kenfine@nospam .nospam> wrote in message
        > | news:un5vTzD5FH A.2364@TK2MSFTN GP12.phx.gbl...
        > | >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(even t);");
        > | > body.Attributes .Add("onKeyUp", "highlight(even t);");
        > | >
        > | > 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
        > | >
        > | >
        > |
        > |
        > |
        >[/color]


        Comment

        • Steven Cheng[MSFT]

          #5
          Re: basic: asp.net user controls: how to programmaticall y add attribute to all text box controls?

          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: "kenfine@nospam .nospam" <kenfine@u.wash ington.edu>
          | From: <kenfine@nospam .nospam>
          | References: <un5vTzD5FHA.23 64@TK2MSFTNGP12 .phx.gbl>
          <Oy4u3tE5FHA.12 52@TK2MSFTNGP10 .phx.gbl>
          <wf1l8NF5FHA.28 80@TK2MSFTNGXA0 1.phx.gbl>
          | Subject: Re: basic: asp.net user controls: how to programmaticall y 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: <ewMp52H5FHA.38 80@TK2MSFTNGP12 .phx.gbl>
          | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
          | NNTP-Posting-Host: idea.urel.washi ngton.edu 128.95.9.12
          | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
          | Xref: TK2MSFTNGXA01.p hx.gbl
          microsoft.publi c.dotnet.framew ork.aspnet:1369 61
          | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
          |
          | Thanks to everyone. This is the right approach (and I should have
          remembered
          | it! :)
          |
          | -KF
          |
          | "Steven Cheng[MSFT]" <stcheng@online .microsoft.com> wrote in message
          | news:wf1l8NF5FH A.2880@TK2MSFTN GXA01.phx.gbl.. .
          | > 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" <here@now.com >
          | > | References: <un5vTzD5FHA.23 64@TK2MSFTNGP12 .phx.gbl>
          | > | Subject: Re: basic: asp.net user controls: how to programmaticall y 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: <Oy4u3tE5FHA.12 52@TK2MSFTNGP10 .phx.gbl>
          | > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
          | > | NNTP-Posting-Host: host81-137-199-51.in-addr.btopenworl d.com
          | > 81.137.199.51
          | > | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
          | > | Xref: TK2MSFTNGXA01.p hx.gbl
          | > microsoft.publi c.dotnet.framew ork.aspnet:1368 57
          | > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
          | > |
          | > | using System;
          | > |
          | > | namespace WebControlLibra ry1
          | > | {
          | > | /// <summary>
          | > | /// Summary description for NewTextBox.
          | > | /// </summary>
          | > | public class NewTextBox : System.Web.UI.W ebControls.Text Box
          | > | {
          | > | public NewTextBox()
          | > | {
          | > | //
          | > | // TODO: Add constructor logic here
          | > | //
          | > |
          | > | this.Attributes .Add("onClick", "javascript:ale rt('Hello World')");
          | > |
          | > | }
          | > | }
          | > | }
          | > |
          | > | }
          | > |
          | > |
          | > | --
          | > | Best Regards
          | > |
          | > | The Inimitable Mr Newbie º¿?
          | > <kenfine@nospam .nospam> wrote in message
          | > | news:un5vTzD5FH A.2364@TK2MSFTN GP12.phx.gbl...
          | > | >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(even t);");
          | > | > body.Attributes .Add("onKeyUp", "highlight(even t);");
          | > | >
          | > | > 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
          | > | >
          | > | >
          | > |
          | > |
          | > |
          | >
          |
          |
          |

          Comment

          Working...