By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,275 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,275 IT Pros & Developers. It's quick & easy.

How to clear values from dynamically created text boxes

P: 31
can anybody tel me how to clear values from dynamically created text boxes?? using a clear button.. this is the code used to create dynamic text boxes.. if i press clear button then it must clear all the values entered in al the textboxes



Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If IsPostBack Then
Try
If Not TextBox1.Text Is String.Empty Then
numofper = TextBox1.Text

ReDim TxtDyn1(numofper)
ReDim TxtDyn2(numofper)
ReDim TxtDyn3(numofper)
ReDim TxtDyn4(numofper)

Else
Exit Sub
End If

'To create the dynamic text box and add the controls to panel, save them in session state

For i As Integer = 0 To numofper - 1
TxtDyn1(i) = New TextBox
TxtDyn1(i).EnableViewState = True
Panel1.Controls.Add(TxtDyn1(i))
textdynamic1.Add(textdynamic1)
Next
For j As Integer = 0 To numofper - 1
TxtDyn2(j) = New TextBox
TxtDyn2(j).EnableViewState = True
Panel2.Controls.Add(TxtDyn2(j))
textdynamic2.Add(textdynamic2)
Next
For k As Integer = 0 To numofper - 1
TxtDyn3(k) = New TextBox
TxtDyn3(k).EnableViewState = True
Panel3.Controls.Add(TxtDyn3(k))
textdynamic3.Add(textdynamic3)
Next
For l As Integer = 0 To numofper - 1
TxtDyn4(l) = New TextBox
TxtDyn4(l).EnableViewState = True
Panel4.Controls.Add(TxtDyn4(l))
textdynamic4.Add(textdynamic4)
TxtDyn4(l).Enabled = False
Next

Catch ex As Exception
MsgBox("Enter a valid Number")
End Try
End If

End Sub
Oct 13 '08 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 750
PRR
Loop through all the controls in your panel... then clear them....
Expand|Select|Wrap|Line Numbers
  1. TextBox v;
  2. foreach (Control ctrl in Panel1.Controls)
  3.         {
  4.             if (ctrl is TextBox)
  5.             {
  6.                 v=(TextBox)ctrl;
  7.                 v.Text =string.Empty;
  8.             }
  9.         }
  10. }
  11.  
Oct 14 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.