What is the difference between
and
in ASP.NET?
When should you use one over the other?
What is the difference between
and
in ASP.NET?
When should you use one over the other?
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.
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
There is a good article at startvbnet here.
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.
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 BackImageUr
l property to display a custom image for the Panel control. Use the ScrollBars
property to specify scroll bars for the control.
Small differences when rendering HTML: a PlaceHolder control will render nothing, but Panel control will render as a More information at ASP.NET Forums I weird bug* in visual studio 2010, if you put controls inside a Placeholder it does not render them in design view mode. This is especially true for Hidenfields and Empty labels. I would love to use placeholders instead of panels but I hate the fact I cant put other controls inside placeholders at design time in the GUI. As mentioned in other answers, the Panel generates a Why a PlaceHolder? Since it generates no tag of it's own you can use it safely inside other element that cannot contain a You can also use a PlaceHolder to control the Visibility of a group of Controls without wrapping it in a Why a Panel It generates it's own But the most useful feature is the Try the above snippet by pressing 回答4:
回答5:
Row 1 DefaultButton
property. When the ID matches a Button in the Panel it will trigger a Form Post with Validation when enter
is pressed inside a TextBox. Now a user can submit the Form without pressing the Button.
enter
inside TextBox1