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. Apply action to all TextBoxes on Page

Apply action to all TextBoxes on Page

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
7 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.
  • M Offline
    M Offline
    munklefish
    wrote on last edited by
    #1

    Hi, Anyone know how to apply an action to all objects of a given type? eg if i wanted to reset the text in all labels on a page? Thanks Merry Christmas!

    K V T I 4 Replies Last reply
    0
    • M munklefish

      Hi, Anyone know how to apply an action to all objects of a given type? eg if i wanted to reset the text in all labels on a page? Thanks Merry Christmas!

      K Offline
      K Offline
      Ketty Avashia
      wrote on last edited by
      #2

      If u r trying to find a solution on postback to reset all controls of a type - u can loop through all child controls of a page check the type and depending on that take an action. If u r trying to find a solution by java script - use a naming style (like txtreset_1) of the set u want to treat alike. In ur function loop through all controls and with the help of regex (for txtreset_) find matches (using regex match funtion) to ur naming style. for all the match that u find take the desired action. Hope this gives u some idea of how to go about. Ketty

      1 Reply Last reply
      0
      • M munklefish

        Hi, Anyone know how to apply an action to all objects of a given type? eg if i wanted to reset the text in all labels on a page? Thanks Merry Christmas!

        V Offline
        V Offline
        VenkataRamana Gali
        wrote on last edited by
        #3

        Hi, Not only label or TextBox we can do any operation for all controls. for ex: we neeed to clear all the vlaues in textboxes or labels check this javascript function function ClearValues() { var oObject=document.Form1.elements; for (i = 0; i < oObject.length; i++) { if(oObject[i].name !="__VIEWSTATE" && oObject[i].type= "text") { //alert(oObject[i].name); oObject[i].value=""; } } In case of asp.net Label, after rendering into the browser it will be div. so check the each control name using alert box bye regards GV Ramana

        1 Reply Last reply
        0
        • M munklefish

          Hi, Anyone know how to apply an action to all objects of a given type? eg if i wanted to reset the text in all labels on a page? Thanks Merry Christmas!

          T Offline
          T Offline
          ToddHileHoffer
          wrote on last edited by
          #4

          You will need a recursive function. Try this. Public Sub resetControl(ByVal cntrl As Web.UI.Control) Dim x As Web.UI.Control For Each x In cntrl.Controls If TypeOf x Is TextBox Then Dim txt As New TextBox txt = CType(x, TextBox) txt.Text = "" End If If x.HasControls = True Then resetControl(x) End If Next End Sub 'Call from a button click Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click resetControl(Page) End Sub "People who never make mistakes, never do anything." My Blog

          M 1 Reply Last reply
          0
          • T ToddHileHoffer

            You will need a recursive function. Try this. Public Sub resetControl(ByVal cntrl As Web.UI.Control) Dim x As Web.UI.Control For Each x In cntrl.Controls If TypeOf x Is TextBox Then Dim txt As New TextBox txt = CType(x, TextBox) txt.Text = "" End If If x.HasControls = True Then resetControl(x) End If Next End Sub 'Call from a button click Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click resetControl(Page) End Sub "People who never make mistakes, never do anything." My Blog

            M Offline
            M Offline
            munklefish
            wrote on last edited by
            #5

            ToddHileHoffer, That looks like the kind of thing i need thanks! Anyone know how to do this in c# ?? THANKS!!!!!

            T 1 Reply Last reply
            0
            • M munklefish

              ToddHileHoffer, That looks like the kind of thing i need thanks! Anyone know how to do this in c# ?? THANKS!!!!!

              T Offline
              T Offline
              ToddHileHoffer
              wrote on last edited by
              #6

              This article might help you figure it out. link "People who never make mistakes, never do anything." My Blog -- modified at 15:20 Tuesday 27th December, 2005

              1 Reply Last reply
              0
              • M munklefish

                Hi, Anyone know how to apply an action to all objects of a given type? eg if i wanted to reset the text in all labels on a page? Thanks Merry Christmas!

                I Offline
                I Offline
                Ista
                wrote on last edited by
                #7

                javascript has an "is" function to tell whether the control is of a certain type. But its better to loop it in code. although you would have to check inside and containers on the form. I'm not an expert yet, but I play one at work. Yeah and here too.

                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