views:

6980

answers:

3

What is the difference between Panel and PlaceHolder in ASP.NET?

+18  A: 

A panel expands to a span (or a div), with it's content within it. A placeholder is just that, a placeholder that's replaced by whatever you put in it.

Steven Robbins
A panel becomes a DIV
GoodEnough
It can become a Span too, dependant on the version of ASP.Net and the browser it's rendering too.
Steven Robbins
Meh, don't get me started with BrowserCaps - it can also become a single cell table in .Net 1.1 on "Downlevel" browsers.
Zhaph - Ben Duguid
Heh, I tried to force downlevel table rendering out of my mind.. thanks for bringing that back up :-)
Steven Robbins
+15  A: 

Hey ansh

The Placeholder does not render any tags for itself, so it is great for grouping content without the overhead of outer HTML tags.

The Panel does have outer HTML tags but does have some cool extra properties.

  • BackImageUrl: Gets/Sets the background image's URL for the panel

  • HorizontalAlign: Gets/Sets the
    horizontal alignment of the parent's contents

  • Wrap: Gets/Sets whether the
    panel's content wraps

There is a good article at startvbnet here.

Ray Booysen
Another cool feature to an asp:Panel is that it has a DefaultButton property, telling it which button to click if the user presses enter on their keyboard. Handy if you have multiple panels and buttons on the same page that need to work with the enter button.
Alex York
+4  A: 

PlaceHolder control:

Use the PlaceHolder control as a container to store server controls that are dynamically added to the Web page. The PlaceHolder control does not produce any visible output and is used only as a container for other controls on the Web page. You can use the Control.Controls collection to add, insert, or remove a control in the PlaceHolder control.

Panel control:

The Panel control is a container for other controls. It is especially useful when you want to generate controls programmatically, hide/show a group of controls, or localize a group of controls.

The Direction property is useful for localizing a Panel control's content to display text for languages that are written from right to left, such as Arabic or Hebrew.

The Panel control provides several properties that allow you to customize the behavior and display of its contents. Use the BackImageUrl property to display a custom image for the Panel control. Use the ScrollBars property to specify scroll bars for the control.

Render:

PlaceHolder control will render noting, but Panel control will render as a DIV.

More information, please see the following links:

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.placeholder.aspx (PlaceHolder Class)

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.panel.aspx (Panel Class)

from: http://forums.asp.net/p/1162201/1929627.aspx#1929627

ecleel