Home All Groups Group Topic Archive Search About
Author
21 Mar 2005 5:15 PM
anonymous
I have mycontrol as custom control and I need to get some
data from a control
on a different page. My code is below. It is working
perfectly fine, but since
I have 10 more label to check is it some how I can make
this code is more
compact?
If CType(myconrtol.FindControl("lblCompany"),
Label).Visible = True Then
            dr(0) = CType(myconrtol.FindControl
("lblCompany"), Label).Text()
            dr(1) = myconrtol.Company
            dt.Rows.Add(dr)
            dr = dt.NewRow()
        End If

        If CType(myconrtol.FindControl("lblPlanName"),
Label).Visible = True Then
            dr(0) = CType(myconrtol.FindControl
("lblPlanName"), Label).Text()
            dr(1) = myconrtol.PlanName
            dt.Rows.Add(dr)
            dr = dt.NewRow()

        End If

Author
21 Mar 2005 6:20 PM
Jason
Hello,
Assuming these controls are all part of a page, try looping through all
of the controls on the page...

For Each ctl In Me.Controls(1).Controls
                Try
                  ...
                Catch
                End Try
Next

Jason
Author
21 Mar 2005 7:36 PM
anonymous
But I do I get to this code?
dr(0) = CType(mycontrol.FindControl("lblCompany"),
Label).Text()
dr(1) = mycontrol.Company
dt.Rows.Add(dr)
Author
21 Mar 2005 8:11 PM
anonymous
Here is what I did based on your post, however I am not
getting back the right controls name in custom mycontrols.
For Each ctl In mycontrols.Controls 'Me.Controls
(1).Controls
            Dim tb As Label
            Dim tx As TextBox
            If TypeOf ctl Is Label Then
                tb = CType(ctl, Label)
                dr(0) = tb.Text
            ElseIf TypeOf ctl Is TextBox Then
                tx = CType(ctl, TextBox)
                dr(0) = tx.Text
            Else
            End If
            dt.Rows.Add(dr)
            dr = dt.NewRow()
        Next