|
-
May 28th, 2005, 07:45 AM
#1
Thread Starter
Hyperactive Member
how to loop throught all label and button controls of myPage
I would like to loop throught all label and button controls of myPage and modifie their text property (in fact I want to translate the text depending on the language of the user).
I tried this :
VB Code:
For Each myControl As Control In Page.Controls
Dim test As String = myControl.ID
ListBox1.Items.Add(myControl.ID)
Next
but this does not give me the list of all controls.
I thought that I could loop through all controls, test for each if it is a control or button and then change the property .text to a new value depending on their old value.
Would to nice if anybody could give me a littel help...
Thank you in advance!
Fabian
-
May 28th, 2005, 12:11 PM
#2
Re: how to loop throught all label and button controls of myPage
You will need a recursive function.
Here is what you need.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.ListBox1.Items.Clear()
For Each ctl As Control In Me.Controls
GetControls(ctl)
Next
End Sub
Private Function GetControls(ByVal ctl As Control)
For Each ct As Control In ctl.Controls
If ct.GetType Is GetType(Label) Then
Dim lbl As Label
lbl = CType(ct, Label)
Me.ListBox1.Items.Add("ID:" & lbl.ID & " Text:" & lbl.Text)
lbl.Text = "New Text"
End If
If ct.Controls.Count > 0 Then
GetControls(ct)
End If
Next
End Function
[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 : 
-
May 28th, 2005, 12:37 PM
#3
Thread Starter
Hyperactive Member
Re: how to loop throught all label and button controls of myPage
juste perfect - exactly what I was looking for ... and even prepared for consumption. I had nothing to do.
Thank you very much!
Fabian
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
|