Home All Groups Group Topic Archive Search About

Retrieving all properties of control how to -asp.net

Author
15 Nov 2006 5:56 PM
mpar16
hi,
  could please help me to retrieve properties of a control, i got a
scenario to read all available properties and its current assigned
values for different controls in project. i tried with reflector tool
but it giving properties of classes. I am not sure how to get property
and its value. right now i have open property window for each control
(Properties window) and noting down from a-z properties and its values.
could you help me to get programmatically all properties and its value?

Author
16 Nov 2006 8:36 PM
MikeS
Given a texbox and a button.

Imports System.Reflection
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Dump(TextBox1)
    End Sub
    Private Sub Dump(ByVal o As Object)
        Dim t As Type = o.GetType
        For Each mi As MemberInfo In t.GetMembers
            If mi.MemberType = MemberTypes.Property Then
                Dim prop As Object = t.InvokeMember(mi.Name,
BindingFlags.GetProperty, Nothing, o, Nothing, Nothing)
                Try
                    Response.Write(mi.Name & "=" & prop.ToString &
"<br>")
                Catch ex As Exception
                End Try
            End If
        Next
    End Sub
End Class
Author
17 Nov 2006 4:32 AM
mpar16
Thanks Mike Let me try i have been googling to get a clue
MikeS wrote:
Show quoteHide quote
> Given a texbox and a button.
>
> Imports System.Reflection
> Partial Class _Default
>     Inherits System.Web.UI.Page
>     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
>         Dump(TextBox1)
>     End Sub
>     Private Sub Dump(ByVal o As Object)
>         Dim t As Type = o.GetType
>         For Each mi As MemberInfo In t.GetMembers
>             If mi.MemberType = MemberTypes.Property Then
>                 Dim prop As Object = t.InvokeMember(mi.Name,
> BindingFlags.GetProperty, Nothing, o, Nothing, Nothing)
>                 Try
>                     Response.Write(mi.Name & "=" & prop.ToString &
> "<br>")
>                 Catch ex As Exception
>                 End Try
>             End If
>         Next
>     End Sub
> End Class