473,386 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Accessing usercontrol in placeholder

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
Oct 13 '06 #1
3 1600
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 Namehere if x is not null

"David Lozzi" <dl****@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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
Oct 14 '06 #2
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

"Siva M" <sh******@online.excite.comwrote in message
news:OU**************@TK2MSFTNGP02.phx.gbl...
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 Namehere if x is not null

"David Lozzi" <dl****@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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


Oct 14 '06 #3
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

"Siva M" <sh******@online.excite.comwrote in message
news:OU**************@TK2MSFTNGP02.phx.gbl...
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 Namehere if x is not null

"David Lozzi" <dl****@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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



Oct 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lars Pedersen | last post by:
My app is adding a usercontrol at runtime. How is it possible to remove this usercontrol? Have tried Page.Controls.Remove(UserControl);, but that wont do the trick - any suggestions? -Lars
0
by: Sebastian Hiller | last post by:
Hello, i'm new to .Net (i'm using VB as language and i'm working in the code-behind mode) and i can't solve the following problem: I have a WebForm and want to Add a UserControl...
2
by: Ben de Vette | last post by:
Hi, I like to load a UserControl onto a placeholder with some more control then just doing protected System.Web.UI.WebControls.PlaceHolder placeHolder; UserControl ascx =...
2
by: John | last post by:
Hi all, I need to access properties (as well as a couple of methods) from one web page embedded within a usercontrol (with an iFrame inside it) to another usercontrol embedded on the main page...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
1
by: Tim | last post by:
Greetings! I have a UserControl. On this UserControl is a Panel and a RadioButtonList. The Panel's Visible property is set to false by default. When the user selects a particular...
2
by: Vivek Sharma | last post by:
Hi There, I have a situation where I wish to load the controls dynamically on the basis of user role. Hence, I am using this code. if (UserRole == "IS Administrator") { Control UC1 =...
0
by: dkode | last post by:
Hello, I know this can be done, but it's beyond me at the moment, Here is my inheritance chain: class NavRole : UserControl { protected void AddSubmenu(string submenuFile); } class artist...
0
by: dkode | last post by:
Hello, I know this can be done, but it's beyond me at the moment, Here is my inheritance chain: class NavRole : UserControl { protected void AddSubmenu(string submenuFile);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.