Clear All Text Boxes on Submit

K

Kemp

I need help with clearing the text boxes when the submit
button is clicked. I am developing a web application. I
have tried placing the following code in the button_click
event, but this doesn't work.

Dim c As Control

For Each c In Me.Controls
If TypeOf(c) Is TextBox Then
CType(c, TextBox).Text = ""
End If
Next

Thanks,
 
A

Armin Zingler

Kemp said:
I need help with clearing the text boxes when the submit
button is clicked. I am developing a web application. I
have tried placing the following code in the button_click
event, but this doesn't work.

"Doesn't work" is rarely a good description. ;-)
Dim c As Control

For Each c In Me.Controls
If TypeOf(c) Is TextBox Then

If TypeOf c Is TextBox Then
CType(c, TextBox).Text = ""
End If
Next

In a WinForms application, this processes only the controls on the Form, not
those contained in controls on the Form. Maybe/probably it is the same in a
Web application.
 
C

Cor

Hi Kemp

It does work not normal on a WebForm as documentated, I thought this was
working.

\\\
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim frm As Control = Me.FindControl("Form1")
Dim ctl As Control
For Each ctl In frm.Controls
Dim tb As TextBox
If TypeOf ctl Is TextBox Then
tb = DirectCast(ctl, TextBox)
tb.Text =""
End If
Next
///

I hope this helps a little bit?

Cor
 
G

Guest

-----Original Message-----


"Doesn't work" is rarely a good description. ;-)


If TypeOf c Is TextBox Then


In a WinForms application, this processes only the controls on the Form, not
those contained in controls on the Form. Maybe/probably it is the same in a
Web application.


--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Sorry about the "Doesn't work" comment. This just seems
like a simple task and I am struggling with it. Is there
a better way to achieve this?
 
C

Cor

Hi Anonymous,

Dit you mean, this?
like a simple task and I am struggling with it. Is there
a better way to achieve this?

:)))))))))))))))) This in not Serious but ment for Armin, you got my answer
in the thread

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top