469,647 Members | 1,706 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

How to clear values from dynamically created text boxes

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
1 1586
PRR
750 Expert 512MB
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.

Similar topics

3 posts views Thread by crjunk | last post: by
2 posts views Thread by Duncan Welch | last post: by
32 posts views Thread by =?Utf-8?B?U2l2?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.