473,779 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Placeholder and UserControl

Hi,

I like to load a UserControl onto a placeholder with some more control then
just doing

protected System.Web.UI.W ebControls.Plac eHolder placeHolder;
UserControl ascx = (UserControl)Pa ge.LoadControl( "myUserControl. ascx");
placeHolder.Con trols.Add(ascx) ;

More something like

UserControl uc = new myUserContol();
uc.Name = "just A Test";
uc.Initialize() ;
placeHolder.Con tols.Add(uc);

The problem lies in the fact that any contols placed in myUserControl are
not instanciated in the second example. Any idea how I get this working?

Thanks,
Ben
Nov 18 '05 #1
2 6748
"Ben de Vette" <Be************ ****@profiler.n l> wrote in message
news:10******** *****@corp.supe rnews.com...
Hi,

I like to load a UserControl onto a placeholder with some more control then just doing

protected System.Web.UI.W ebControls.Plac eHolder placeHolder;
UserControl ascx = (UserControl)Pa ge.LoadControl( "myUserControl. ascx");
placeHolder.Con trols.Add(ascx) ;

More something like

UserControl uc = new myUserContol();
uc.Name = "just A Test";
uc.Initialize() ;
placeHolder.Con tols.Add(uc);

The problem lies in the fact that any contols placed in myUserControl are
not instanciated in the second example. Any idea how I get this working?


When you use LoadControl, the HTML in the .ascx file are compiled. They are
compiled into a class which inherits from the myUserControl class. The .ascx
file isn't touched in your second case.

Is there a reason why you can't use the first way?
--
John Saunders
johnwsaundersii i at hotmail
Nov 18 '05 #2
Thanks,

The reason I want to use the second example is that myUserControl should
load different values, depending on an external source identified by a
string.

So, I want to use the generic myUserControl to be reused over and over
again.

I already got it working with LoadControl().

What I do is:
In the containing Page (Test.aspx)
Create the UserControl with LoadControl
Then I put the newly loaded control into an Hash (control is the key),
an identifying string the value
Then I add the control to a PlaceHolder.

In this page I write a methode which will return the string when the
control is given as argument

In myUserControl
In PageLoad, I try to find the containing Page (test.aspx)
Cast the found page to Test
Call a methode on the Test instance with 'this' as argument
With the retrieved string, I can get a specific field/table from e.g. a
database

But I rather have it working without the callback from the ChildControl.

Ben


"John Saunders" <jo************ **@notcoldmail. com> wrote in message
news:eM******** ******@TK2MSFTN GP11.phx.gbl...
"Ben de Vette" <Be************ ****@profiler.n l> wrote in message
news:10******** *****@corp.supe rnews.com...
Hi,

I like to load a UserControl onto a placeholder with some more control then
just doing

protected System.Web.UI.W ebControls.Plac eHolder placeHolder;
UserControl ascx = (UserControl)Pa ge.LoadControl( "myUserControl. ascx"); placeHolder.Con trols.Add(ascx) ;

More something like

UserControl uc = new myUserContol();
uc.Name = "just A Test";
uc.Initialize() ;
placeHolder.Con tols.Add(uc);

The problem lies in the fact that any contols placed in myUserControl are not instanciated in the second example. Any idea how I get this working?


When you use LoadControl, the HTML in the .ascx file are compiled. They

are compiled into a class which inherits from the myUserControl class. The ..ascx file isn't touched in your second case.

Is there a reason why you can't use the first way?
--
John Saunders
johnwsaundersii i at hotmail

Nov 18 '05 #3

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

Similar topics

4
8803
by: patrick_a | last post by:
Hello, I am trying to insert multiple instances of a custom user control into a placeholder on an aspx page, based on the records retrieved from the database. I use the datareader to loop through the records and I want to create a new instance of the user control for each record and then change the properties of the controls within each user control. The problem is that after I create the new instance of the user control, I get a...
2
4729
by: Mike Speak | last post by:
I have a user control that I want to use to render 4 menu items (retrieved from db) on the top of each of my asp.net pages. The user control defines a table, with one TR and one TD. Within the TD I have a placeholder defined: <asp:PlaceHolder ID="categoriesPlaceHolder" Runat="server" /> In the code behind of the user control, on the Page_Load event I am retrieving data from db and adding controls to the placeholder as
1
2961
by: Dan | last post by:
I have an asp.net page default.aspx with a user control and a placeholder control. <html> <body> <form id="myform" method="post" runat="server" /> <PageHeader:Header id="header1" runat="server" /> <asp:PlaceHolder ID="content" runat="server" /> </form> </body>
9
2454
by: Anders K. Jacobsen [DK] | last post by:
Hi I have this that adds some usercontrol (UCTodays.ascx) to a placeholder foreach(A a in B){ UCTodays ucline = (UCTodays )LoadControl("UCTodays.ascx"); ucline.Initializecontrol(line,alternate); Placeholder1.Controls.Add(ucline); }
0
1272
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 : NavRole {}
0
1554
by: seigo | last post by:
Hello, I faced with the following problem. I have a PlaceHolder on a page and a few UserControls which have custom events, for instance: public delegate void SelectHandler(object sender, SelectEventArgs e); public event SelectHandler OnSelect; protected void Page_Load(object sender, EventArgs e)
2
1451
by: David | last post by:
I have a UserControl loaded into a PlaceHolder and I have a button there which is suppose to load another UserControl into the same PlaceHolder and hide the previous one. Why does the events of the controls that are inside the second UserControl doesn't work the first time I try to rise them?
3
1622
by: David Lozzi | last post by:
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
3
9658
by: Bert | last post by:
Hi I am trying to load my user control in a placeholder, i get an error: c:\inetpub\wwwroot\testinline\WebForm2.aspx.vb(26): Type 'WebUserControl6' is not defined? Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
0
9632
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10302
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.