Loading a User Control With Propertys

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
 

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,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top