System.Reflection and Web User Controls in 3.5

M

MattB

I have some old (.Net 1.1) code that I'm trying to use again in .Net 3.5
and it looks like maybe it needs to be changed to work on 3.5 (or I'm
overlooking something, which is also very possible).

Anyway, I am building a dynamic page that adds and configures User
Controls based on database values. This is based on the old 1.1 code and
it all compiles, but the ucType.GetProperty(Col.ColumnName) always
returns Null. The user control has properties declared as Public that
match the column names, and if I set a break point and try
ucType.GetProperty("MyProperty") in the watch window I still get null,
even if I have a Public Property MyProperty() declared in the codebehind
of the control.

Any suggestions would be appreciated.

Here's the relevant snippet:

--------------------
If Not IsNothing(dtControls) Then
Dim r As DataRow
For Each r In dtControls.Rows
If System.IO.File.Exists(Server.MapPath(".\UserControls\" &
r("Control") & ".ascx")) Then
Dim Ctrl As New UserControl
Dim ucType As Type
Dim ucProperty As System.Reflection.PropertyInfo
Dim Col As DataColumn

Ctrl.LoadControl(".\UserControls\" & r("Control") & ".ascx")
Ctrl.ID = r("Name")
ucType = Ctrl.GetType

For Each Col In dtControls.Columns
ucProperty = ucType.GetProperty(Col.ColumnName) 'this always returns
Nothing
If Not IsNothing(ucProperty) Then
ucProperty.SetValue(Ctrl, Col.ColumnName, Nothing)
End If
Next Col
Panel1.Controls.Add(Ctrl)

End If
Next r
End If
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top