|
-
May 21st, 2005, 05:47 AM
#1
Thread Starter
Junior Member
Web Form Controls Iteration
Hi all,
How to iterate through all or specifice controls on a Web Form using VB?
Thanks
-
May 23rd, 2005, 04:25 AM
#2
Frenzied Member
Re: Web Form Controls Iteration
You can iterate through the Page.Controls ControlCollection.
Code:
For Each x AS Control In Page.Controls
'Do Stuff
Next
DJ
If I have been helpful please rate my post. If I haven't tell me!
-
Jun 5th, 2005, 12:56 AM
#3
Thread Starter
Junior Member
Re: Web Form Controls Iteration
Thanks for your reply.
I did this. How to get the value of the found textbox control.
For i = 0 To MyForm.Controls.Count - 1
x = MyForm.Controls(i).GetType.ToString
Select Case x
Case "System.Web.UI.WebControls.TextBox"
'/ The following line will print the ID of the control.
Response.Write(MyForm.Controls(i).ID)
Case "System.Web.UI.WebControls.DropDownList"
Case "System.Web.UI.WebControls.Button"
Case "System.Web.UI.WebControls.RadioButton"
Case "System.Web.UI.WebControls.CheckBox"
Case "System.Web.UI.HtmlControls.HtmlInputCheckBox"
Case "System.Web.UI.HtmlControls.HtmlInputButton"
End Select
Next
-
Jun 5th, 2005, 06:33 AM
#4
Re: Web Form Controls Iteration
This loop will only work if you have no container in your Page, if you have containers then you will need recursing function. I have posted an example here, that should be exactly what you are looking for.
http://www.vbforums.com/showthread.php?t=341665
Instead of "Label" change it to "TextBox" and the rest will be same..
Hope it helps.
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Jun 5th, 2005, 06:47 AM
#5
Thread Starter
Junior Member
Re: Web Form Controls Iteration
Hi,
I posted my running code for iterating through the contols. It's working perfect. Except, I dont know how to get the value of the found textbox control.
Thanks
-
Jun 5th, 2005, 09:37 AM
#6
Re: Web Form Controls Iteration
VB Code:
For i = 0 To MyForm.Controls.Count - 1
dim ct as Control
ct = MyForm.Controls(i)
If ct.GetType Is GetType(TextBox) Then
dim txt As String
txt = CType(ct, TextBox).Text
End If
Next
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Jun 6th, 2005, 12:05 AM
#7
Thread Starter
Junior Member
Re: Web Form Controls Iteration
Great thanks to you Danial
For other visitors who may need this code, here is the full code to iterate through the web form controls and getting the value of the found control. Other types of controls are also listed for you to test and print.
VB Code:
Dim i As Integer
Dim x As string
Dim txt As String
Dim ct As Control
For i = 0 To MyForm.Controls.Count - 1
ct = MyForm.Controls(i)
x = ct.GetType.ToString
Select Case x
Case "System.Web.UI.WebControls.TextBox"
txt = CType(ct, TextBox).Text
Response.Write("TextBox value is: " & txt)
Case "System.Web.UI.WebControls.DropDownList"
txt = CType(ct, DropDownList).SelectedItem.Text
Response.Write("DropDownList value is: " & txt)
Case "System.Web.UI.WebControls.ListBox"
txt = CType(ct, ListBox).SelectedItem.Text
Response.Write("ListBox value is: " & txt)
Case "System.Web.UI.WebControls.Button"
txt = CType(ct, Button).Text
Response.Write("Button value is: " & txt)
Case "System.Web.UI.WebControls.RadioButton"
Case "System.Web.UI.WebControls.CheckBox"
Case "System.Web.UI.HtmlControls.HtmlInputCheckBox"
Case "System.Web.UI.HtmlControls.HtmlInputButton"
End Select
Next
MrAli
-
Jul 30th, 2005, 06:19 AM
#8
Thread Starter
Junior Member
Re: Web Form Controls Iteration
Hi all,
Is it possible that I save the above function in a CLASS.VB so any web form can call it for iteration??
Note: web forms have different names.
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
|