Last post Nov 11, 2009 08:45 PM by MetalAsp.Net
Nov 11, 2009 04:01 PM|Kman02|LINK
I have aspx form with several textboxes.They are populated with values from a table via retrieval of a dataview.
If the row count for the dataview is 0, then I'd like to reset the values in all textboxes. How can I loop through all the textboxes and set a default value?
I've tried the following, but no sucess.
For Each ctrl As Control In Page.Form.Controls
If TypeOf ctrl Is WebControls.TextBox Then
CType(ctrl, WebControls.TextBox).Text = ""
My first For Loop was using Page.Controls but it returned only 1 count.
The textboxes are inside a tabpanel (ajax), so do I have to locate the tabpage and then find all it's controls (for each tabpage)?
Nov 11, 2009 08:45 PM|MetalAsp.Net|LINK
I think you're going to have to use some form of a recursive method call, that will iterate through all the controls in the tabpanel in question.
Something like this:
private void ClearTextBoxes(ControlCollection cc)
foreach (Control control in cc)
if (control is TextBox)
(control as TextBox).Text = "";
You would call this passing in maybe TabPanel1.Controls. Not a VB person, so try the link in my signature to translate.