Nested PlaceHolders

D

DotNetGruven

Hi,

Is there a trick to using nested PlaceHolders?

I have a WebForm that has 3 PlaceHolders on it:

headerPlaceHolder
contentPlaceHolder
footerPlaceHolder

Everything works well until I add a UserControl to the
contentPlaceHolder which has 3 placeHolders on it:

leftContentPlaceHolder
centerContentPlaceHolder
rightContentPlaceHolder

All controls are added to place holders in the Page_Load event
handler.

I'm getting a null reference on the leftContentPlaceHolder.

Any insight into this issue will be greatly appreciated!

TIA,
geo
 
D

DotNetGruven

Additional information!

The problem seems to be with UserControls that I'm using new instead of
Page.LoadControl()!

Some of the user controls that are being used have Properties that cause the
content to be modified. So, I tried using new on them, then with the local
reference, I'd set the properties and then use the local reference to add
the control to the pages controls collection.

So, the question now is:

What is the difference between newing a UserControl and Loading a
UserControl??

TIA
goe
 
S

Steven Cheng[MSFT]

Hi Geo,

Thanks for posting in the community!
From your description, you have a custom ASP.NET UserControl(ascx) and you
used it in a certain web page. You tried both using "new" constrcutor and
the LoadControl( ascx file) to create a new control and found that the
"new" constructor not worked. So you're wondering what''re the differences
bewteen the two means,yes?

As for this question, here are my suggestions on it:
The ASP.NET UserControl is a kind of Template based controls which has its
own template (in the ascx file), something like the include file in the
classic asp. When using it in a certain container page. The ASP.NET runtime
will first compile and generate the UserControl's class instance from the
ascx source template. So generally, there're two means to add a ascx
UserControl into a page:'
1. Statically add it onto page via add UserControl's declaration and tag.

2. Using LoadControl to dynamically load a UserControl instance from an
ascx file.

If you use "new" constructor to create a certain UserControl class
instance, it doesn't load the control's source content from the ascx
template, so it is not actually a complete UserControl instance. I think
you should still use the LoadControl method and then set the certain
properties of the controls before adding it to page.

If you'd like to use "new" constructor to create a certain control instance
like asp.net TextBox or Label, you need to develop a ASP.NET
WebServerControl which is quite different from UserControl.

Here are some tech reference on ASP.NET UserControl and WebSErver Control
in MSDN:

#Web Forms User Controls
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconwebformsusercontro
ls.asp?frame=true

#Composite Control vs. User Control
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconcompositecontrolvsusercontrol.asp

#ASP.NET Server Control Development Basics
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconwebformscontroldev
elopmentbasics.asp?frame=true

Hope these help.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top