|
-
Aug 12th, 2001, 07:17 PM
#1
Thread Starter
Junior Member
Code ? Looping through controls
Code:
Private Sub Reset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Reset.Click
Dim tb As System.Web.UI.WebControls.TextBox
For Each tb In Page.Controls
tb.Text = ""
Next
End Sub
Hi everybody I have a reset button on a form and I want to clear all the textboxes on the form when you hit reset obviously... I don't want to have to go
textbox1.text = ""
textbox2.text = ""
textbox3.text = ""
a zillion times but the code above keep giving me errors anybody have any ideas as to what I'm doing wrong here...
Thanks for your help in advance
-
Aug 12th, 2001, 07:24 PM
#2
PowerPoster
Hi Agent
I am not up to speed on web controls but if it is anything like normal form controls then...
VB Code:
Private Sub Command1_Click()
'This works
Dim lControl As Control
For Each lControl In Me.Controls
If TypeOf lControl Is TextBox Then
lControl.Text = "Me"
End If
Next
End Sub
Private Sub Command2_Click()
'This doesnt.. similar to ur code
Dim lControl As TextBox
For Each lControl In Me.Controls
lControl.Text = "Me"
Next
End Sub
Regards
Stuart
-
Aug 12th, 2001, 10:54 PM
#3
Thread Starter
Junior Member
Thanks Beachbum
Thanks Beachbum for the reply... I knew how to do it in vb but I'm totally stumped with how to do it using VB.Net I tried all sorts of combinations of some of your posted code...
Well I've made a little progress I managed to count all the textboxes on a WinForm with the following code
Woopee
VB Code:
Private Sub Reset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Reset.Click
Dim i As Integer
Dim x As Integer
Try
For i = 0 To form1.Controls.Count - 1
If TypeOf form1.Controls.Item(i) Is TextBox Then
' I need to somehow access each textbox in here
' it would be ideal if I could do something like this
' form1.Controls.Item(i).Text = ""
' but I can't
x += 1
Label1.Text = "There are " & x & " textboxes on your form"
End If
Next
Catch er As Exception
Label1.Text = er.Message
End Try
End Sub
So Please respond if you have any more suggestions this is driving me nutz
-
Aug 12th, 2001, 11:39 PM
#4
PowerPoster
Sorry Agent
Silly me didnt even notice that this post was in .NET forum. So, having never seen .Net, i cant offer any help. Good luck 
Regards
Stuart
-
Aug 13th, 2001, 12:32 AM
#5
Junior Member
Hi AgentBxb
Here is the code to clear all control in windows application of VB.NET
Sub ClearText(ByVal ThisForm As System.Windows.Forms.Form)
Dim ThisControl As System.Windows.Forms.Control
For Each ThisControl In ThisForm.Controls
ThisControl.Text = ""
Next ThisControl
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ClearText(Me)
End Sub
Let me know if it really helpful
kumar
-
Aug 13th, 2001, 10:29 AM
#6
Thread Starter
Junior Member
Hi Kumars
Hey thanks for the code did you get that working in a standard web application cause I'm trying to do it in a Asp.Net Web Application I think it's a little different, cause I couldn't get it working so I just quite trying to be fancy and went with
textbox1.text = ""
textbox2.text = ""
textbox3.text = ""
Not as elegant but oh well what can you do
-
Aug 13th, 2001, 10:41 PM
#7
Junior Member
Hi
May i get ur email id
kumars
-
Aug 14th, 2001, 04:49 PM
#8
Thread Starter
Junior Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|