Apply action to all TextBoxes on Page
-
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!
-
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!
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
-
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!
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 -
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!
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 -
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 BlogToddHileHoffer, That looks like the kind of thing i need thanks! Anyone know how to do this in c# ?? THANKS!!!!!
-
ToddHileHoffer, That looks like the kind of thing i need thanks! Anyone know how to do this in c# ?? THANKS!!!!!
-
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!