P
Peter Afonin
Hello:
I need to clear all textboxes on the webform after the data has been
submitted. How can I do this in one step?
I found a C# code:
// get a reference to your form control
Control frm = FindControl("YourFormID");
foreach(Control ctrl in frm.Controls)
{
TextBox tb = ctrl as TextBox;
if(ctrl!=null)
tb.Text="";
}
I tried to interpret it into VB.Net like this:
Dim frm As Control = Me.FindControl("Form1")
Dim ctl As Control
For Each ctl In frm.Controls
Dim tb As TextBox = CType(ctl, TextBox)
tb.Text = ""
Next
but I get an error message: "Specified cast is not valid".
So this line is incorrect: Dim tb As TextBox = CType(ctl, TextBox)
Could you help me please?
Thank you,
I need to clear all textboxes on the webform after the data has been
submitted. How can I do this in one step?
I found a C# code:
// get a reference to your form control
Control frm = FindControl("YourFormID");
foreach(Control ctrl in frm.Controls)
{
TextBox tb = ctrl as TextBox;
if(ctrl!=null)
tb.Text="";
}
I tried to interpret it into VB.Net like this:
Dim frm As Control = Me.FindControl("Form1")
Dim ctl As Control
For Each ctl In frm.Controls
Dim tb As TextBox = CType(ctl, TextBox)
tb.Text = ""
Next
but I get an error message: "Specified cast is not valid".
So this line is incorrect: Dim tb As TextBox = CType(ctl, TextBox)
Could you help me please?
Thank you,