Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. To clear textboxes in the content page

To clear textboxes in the content page

Scheduled Pinned Locked Moved ASP.NET
csharp
13 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S SunithaNallana

    hi... i am having a contentpage which has many textboxes.Pls let me know the code(in c#)to clear textboxes at a button click. SunithaNallana

    P Offline
    P Offline
    Prateek G
    wrote on last edited by
    #4

    Not a good way of doing but you can try ArrayList al = new ArrayList(); foreach(Control c in Page.Form.Controls) { if(c.GetType() == typeof(TextBox)) { al.Add(c); } } foreach(TextBox t in al) { t.Text = ""; } But There should be any other better way to do it. here I have assumed that you have all the textboxes in same form. In case its not true You will have to loop through all the forms. Happy Birthday!!!:laugh:

    S N S 3 Replies Last reply
    0
    • P Prateek G

      Not a good way of doing but you can try ArrayList al = new ArrayList(); foreach(Control c in Page.Form.Controls) { if(c.GetType() == typeof(TextBox)) { al.Add(c); } } foreach(TextBox t in al) { t.Text = ""; } But There should be any other better way to do it. here I have assumed that you have all the textboxes in same form. In case its not true You will have to loop through all the forms. Happy Birthday!!!:laugh:

      S Offline
      S Offline
      Sun Rays
      wrote on last edited by
      #5

      Prateek G wrote:

      ArrayList al = new ArrayList(); foreach(Control c in Page.Form.Controls) { if(c.GetType() == typeof(TextBox)) { al.Add(c); } } foreach(TextBox t in al) { t.Text = ""; }

      No need to loop 2 Times. foreach(Control c in Page.Form.Controls) { if(c.GetType() == typeof(TextBox)) { Textbox t = (Textbox)c; t.Text = ""; } }

      Thanks, Sun Rays

      1 Reply Last reply
      0
      • S SunithaNallana

        yes to clear textboxes values SunithaNallana

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #6

        Content place holder will have Control collection property. Iterate through each item and check if it is TextBox. If yes clear the text.

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

        S 1 Reply Last reply
        0
        • P Prateek G

          Not a good way of doing but you can try ArrayList al = new ArrayList(); foreach(Control c in Page.Form.Controls) { if(c.GetType() == typeof(TextBox)) { al.Add(c); } } foreach(TextBox t in al) { t.Text = ""; } But There should be any other better way to do it. here I have assumed that you have all the textboxes in same form. In case its not true You will have to loop through all the forms. Happy Birthday!!!:laugh:

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #7

          Prateek G wrote:

          foreach(Control c in Page.Form.Controls)

          This will clear all textbox controls in page. I think question is how to clear the textbox in content place holder.

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

          S 1 Reply Last reply
          0
          • S SunithaNallana

            hi... i am having a contentpage which has many textboxes.Pls let me know the code(in c#)to clear textboxes at a button click. SunithaNallana

            S Offline
            S Offline
            Sarani Ravindran
            wrote on last edited by
            #8

            Try this and call this function on the server side. < script > function Clear() { obj=document.getElementsByTagName("INPUT"); for(i=0;i< obj.length;i++) { if ((obj[i].type == "text")) { obj[i].value = ""; } } < /script > Let me know whether you got the solution.:) God is always with you.

            N 1 Reply Last reply
            0
            • S Sarani Ravindran

              Try this and call this function on the server side. < script > function Clear() { obj=document.getElementsByTagName("INPUT"); for(i=0;i< obj.length;i++) { if ((obj[i].type == "text")) { obj[i].value = ""; } } < /script > Let me know whether you got the solution.:) God is always with you.

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #9

              Saranya Devi wrote:

              function Clear() { obj=document.getElementsByTagName("INPUT"); for(i=0;i< obj.length;i++) { if ((obj[i].type == "text")) { obj[i].value = ""; } }

              This will clear all textboxes, not in the controls in content page

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

              S 1 Reply Last reply
              0
              • N N a v a n e e t h

                Saranya Devi wrote:

                function Clear() { obj=document.getElementsByTagName("INPUT"); for(i=0;i< obj.length;i++) { if ((obj[i].type == "text")) { obj[i].value = ""; } }

                This will clear all textboxes, not in the controls in content page

                All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

                S Offline
                S Offline
                SunithaNallana
                wrote on last edited by
                #10

                thank u all:rose: i cleared my doubt. i have done it this way... 1.in the master page i put a property block in which i wrote public ContentPlaceHolder CPH { get{return ContentPlaceHolderid;} } 2.i made the content page strongly typed ie.. 3.in button click function foreach(control c in Master.CPH.Controls) { if(c.getType().Name == "TextBox") { (c as TextBox).Text =""; } } SunithaNallana

                1 Reply Last reply
                0
                • N N a v a n e e t h

                  Content place holder will have Control collection property. Iterate through each item and check if it is TextBox. If yes clear the text.

                  All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

                  S Offline
                  S Offline
                  SunithaNallana
                  wrote on last edited by
                  #11

                  thank u all:rose: i cleared my doubt. i have done it this way... 1.in the master page i put a property block in which i wrote public ContentPlaceHolder CPH { get{return ContentPlaceHolderid;} } 2.i made the content page strongly typed ie.. 3.in button click function foreach(control c in Master.CPH.Controls) { if(c.getType().Name == "TextBox") { (c as TextBox).Text =""; } } SunithaNallana

                  1 Reply Last reply
                  0
                  • N N a v a n e e t h

                    Prateek G wrote:

                    foreach(Control c in Page.Form.Controls)

                    This will clear all textbox controls in page. I think question is how to clear the textbox in content place holder.

                    All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

                    S Offline
                    S Offline
                    SunithaNallana
                    wrote on last edited by
                    #12

                    thank u all:rose: i cleared my doubt. i have done it this way... 1.in the master page i put a property block in which i wrote public ContentPlaceHolder CPH { get{return ContentPlaceHolderid;} } 2.i made the content page strongly typed ie.. 3.in button click function foreach(control c in Master.CPH.Controls) { if(c.getType().Name == "TextBox") { (c as TextBox).Text =""; } } SunithaNallana

                    1 Reply Last reply
                    0
                    • P Prateek G

                      Not a good way of doing but you can try ArrayList al = new ArrayList(); foreach(Control c in Page.Form.Controls) { if(c.GetType() == typeof(TextBox)) { al.Add(c); } } foreach(TextBox t in al) { t.Text = ""; } But There should be any other better way to do it. here I have assumed that you have all the textboxes in same form. In case its not true You will have to loop through all the forms. Happy Birthday!!!:laugh:

                      S Offline
                      S Offline
                      SunithaNallana
                      wrote on last edited by
                      #13

                      thank u Prateek.G for wishing me on my birthday.:rose: SunithaNallana

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups