Accessing usercontrol in placeholder

D

David Lozzi

Howdy,

I'm using a PlaceHolder to dynamically display a user control based on a
users selection. This part works great. However how do I get to the
properties of that user control? I have public properties setup but I dont
know how to access that use control...

Thanks!!

David
 
S

Siva M

Not sure if I fully understood your question, but to access the dynamic user
control here is one way:

UserControl x = (UserControl)Panel.FindControl ("<ID assigned to the UC>");
// Use x.<Property Name> here if x is not null

Howdy,

I'm using a PlaceHolder to dynamically display a user control based on a
users selection. This part works great. However how do I get to the
properties of that user control? I have public properties setup but I dont
know how to access that use control...

Thanks!!

David
 
D

David Lozzi

I think tried that, see below...

Dim adv As UserControl = phSearch.FindControl(DeptCode)

addqry = adv.Attributes.Item("SearchString")

OR

addqry = CType(adv.FindControl("btnSearch"), Button).Text


and here's the code I use to put the control into the place holder

Dim srch As UserControl = Page.LoadControl("~/common/advsrc_" & DeptCode &
".ascx")

srch.ID = DeptCode

phSearch.Controls.Add(srch)


And then it errors like so

System.NullReferenceException: Object reference not set to an instance of an
object.

I'm guessing the Attributes.Item is not right to get a Property but I
figured I should be able to get the serach button....

Thanks!!

David
 
D

David Lozzi

I think tried that, see below...

Dim adv As UserControl = phSearch.FindControl(DeptCode)

addqry = adv.Attributes.Item("SearchString")

OR

addqry = CType(adv.FindControl("btnSearch"), Button).Text


and here's the code I use to put the control into the place holder

Dim srch As UserControl = Page.LoadControl("~/common/advsrc_" & DeptCode &
".ascx")

srch.ID = DeptCode

phSearch.Controls.Add(srch)


And then it errors like so

System.NullReferenceException: Object reference not set to an instance of an
object.

I'm guessing the Attributes.Item is not right to get a Property but I
figured I should be able to get the serach button....

Thanks!!

David
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top