Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Nested PlaceHolders

Reply
Thread Tools

Nested PlaceHolders

 
 
DotNetGruven
Guest
Posts: n/a
 
      03-02-2004
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


 
Reply With Quote
 
 
 
 
DotNetGruven
Guest
Posts: n/a
 
      03-02-2004
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

"DotNetGruven" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      03-03-2004
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...ormsusercontro
ls.asp?frame=true

#Composite Control vs. User Control
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconcompositecontrolvsusercontrol.asp

#ASP.NET Server Control Development Basics
http://msdn.microsoft.com/library/en...ormscontroldev
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

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      03-05-2004
Hi Geo,

Have you had a chance to check out my suggestions or have you got any
further ideas on this issue? If you have any thing unclear, please feel
free to post here.


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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Failed to load viewstate when dynamically adding controls in placeholders Sinisa Ruzin ASP .Net 0 10-07-2004 05:31 PM
Passing Parameters to User Controls that are Dynamically Loaded in Placeholders Josh ASP .Net 1 05-26-2004 12:42 AM
loading using controls into placeholders buran ASP .Net 1 04-06-2004 05:22 PM
PlaceHolders Colin Basterfield ASP .Net 5 12-24-2003 04:15 AM
Re: UserControl, user defined property, and placeholders Bill Belliveau ASP .Net 0 08-19-2003 10:13 PM



Advertisments