K
kjok
I have a usercontrol with som propertys. I want to make a public
function that loads this control, add the values to the propertys and
put the control in a placeholder. The code remains in the App_Code
Directory.
My problem is that the control(as far as i know) doesnt load. Here is
the Code
Dim toc As New UserControl
toc.AppRelativeTemplateSourceDirectory =
"~/application/controls/alfaSearch"
toc.AppRelativeVirtualPath =
"~/application/controls/alfaSearch/alfasearch.ascx"
toc.LoadControl("~/application/controls/alfaSearch/alfasearch.ascx")
Dim CurrentType As Type = toc.GetType()
Dim cAttrib As System.Reflection.PropertyInfo =
CurrentType.GetProperty("HiddenField")
Dim cAttrib1 As System.Reflection.PropertyInfo =
CurrentType.GetProperty("CurrentActive")
cAttrib.SetValue(toc, FieldName,
Reflection.BindingFlags.SetProperty, Nothing, Nothing, Nothing)
cAttrib1.SetValue(toc, TmpHiddenAlfa,
Reflection.BindingFlags.SetProperty, Nothing, Nothing, Nothing)
TmpPlaceHolder.Controls.Add(toc)
When i get to "cAttrib.SetValue(toc, FieldName,
Reflection.BindingFlags.SetProperty, Nothing, Nothing, Nothing)"
i get an error "Object Reference not set to an instance of an object"
And toc.controls.count return 0
function that loads this control, add the values to the propertys and
put the control in a placeholder. The code remains in the App_Code
Directory.
My problem is that the control(as far as i know) doesnt load. Here is
the Code
Dim toc As New UserControl
toc.AppRelativeTemplateSourceDirectory =
"~/application/controls/alfaSearch"
toc.AppRelativeVirtualPath =
"~/application/controls/alfaSearch/alfasearch.ascx"
toc.LoadControl("~/application/controls/alfaSearch/alfasearch.ascx")
Dim CurrentType As Type = toc.GetType()
Dim cAttrib As System.Reflection.PropertyInfo =
CurrentType.GetProperty("HiddenField")
Dim cAttrib1 As System.Reflection.PropertyInfo =
CurrentType.GetProperty("CurrentActive")
cAttrib.SetValue(toc, FieldName,
Reflection.BindingFlags.SetProperty, Nothing, Nothing, Nothing)
cAttrib1.SetValue(toc, TmpHiddenAlfa,
Reflection.BindingFlags.SetProperty, Nothing, Nothing, Nothing)
TmpPlaceHolder.Controls.Add(toc)
When i get to "cAttrib.SetValue(toc, FieldName,
Reflection.BindingFlags.SetProperty, Nothing, Nothing, Nothing)"
i get an error "Object Reference not set to an instance of an object"
And toc.controls.count return 0