propertyinfo getvalue

E

ENathan

I've created a web app named "OnePage" and it has only one page, WebForm1. I
added a web control, TextBox1 and set the Text property of TextBox1 equal
to "Text from TextBox1". I've built the project and the .dll resides at
c:\inetpub\wwwroot\onepage\bin\onepage.dll"

How can I retrieve TextBox1's text property with reflection? I cannot figure
out which object to pass into textProperty.GetValue below. I get the
TargetException: Object does not match target type. TIA.

Dim asm As [Assembly]

Dim pageType As Type

Dim pageFieldInfo As FieldInfo

Dim textBoxType As Type

Dim textProperty As PropertyInfo

Dim ValueObject As Object

asm = [Assembly].LoadFrom("c:\inetpub\wwwroot\onepage\bin\onepage.dll")

pageType = asm.GetType(asm.GetName.Name & "." & "WebForm1", True, True)

pageFieldInfo = pageType.GetField("_TextBox1", BindingFlags.Instance Or
BindingFlags.NonPublic)

textBoxType = pageFieldInfo.FieldType

textProperty = textBoxType.GetProperty("Text", BindingFlags.Public Or
BindingFlags.Instance)

ValueObject = textProperty.GetValue(???, Nothing)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top