Property on Custom Control

K

Keld

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
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top