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.GetPrope rty(Col.ColumnN ame) 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.GetPrope rty("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(dtCon trols) Then
Dim r As DataRow
For Each r In dtControls.Rows
If System.IO.File. Exists(Server.M apPath(".\UserC ontrols\" &
r("Control") & ".ascx")) Then
Dim Ctrl As New UserControl
Dim ucType As Type
Dim ucProperty As System.Reflecti on.PropertyInfo
Dim Col As DataColumn
Ctrl.LoadContro l(".\UserContro ls\" & r("Control") & ".ascx")
Ctrl.ID = r("Name")
ucType = Ctrl.GetType
For Each Col In dtControls.Colu mns
ucProperty = ucType.GetPrope rty(Col.ColumnN ame) 'this always returns
Nothing
If Not IsNothing(ucPro perty) Then
ucProperty.SetV alue(Ctrl, Col.ColumnName, Nothing)
End If
Next Col
Panel1.Controls .Add(Ctrl)
End If
Next r
End If
--------------------
Thanks!
-Matt
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.GetPrope rty(Col.ColumnN ame) 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.GetPrope rty("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(dtCon trols) Then
Dim r As DataRow
For Each r In dtControls.Rows
If System.IO.File. Exists(Server.M apPath(".\UserC ontrols\" &
r("Control") & ".ascx")) Then
Dim Ctrl As New UserControl
Dim ucType As Type
Dim ucProperty As System.Reflecti on.PropertyInfo
Dim Col As DataColumn
Ctrl.LoadContro l(".\UserContro ls\" & r("Control") & ".ascx")
Ctrl.ID = r("Name")
ucType = Ctrl.GetType
For Each Col In dtControls.Colu mns
ucProperty = ucType.GetPrope rty(Col.ColumnN ame) 'this always returns
Nothing
If Not IsNothing(ucPro perty) Then
ucProperty.SetV alue(Ctrl, Col.ColumnName, Nothing)
End If
Next Col
Panel1.Controls .Add(Ctrl)
End If
Next r
End If
--------------------
Thanks!
-Matt