Using Panel or PlaceHolder

前端 未结 5 607
迷失自我
迷失自我 2020-12-02 16:33

What is the difference between and in ASP.NET?

When should you use one over the other?

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 17:02

    As mentioned in other answers, the Panel generates a

    in HTML, while the PlaceHolder does not. But there are a lot more reasons why you could choose either one.

    Why a PlaceHolder?

    Since it generates no tag of it's own you can use it safely inside other element that cannot contain a

    , for example:

    Row 1

    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

    and can also be used to wrap a group of Contols. But a Panel has a lot more properties that can be useful to format it's content:

    
        Red text on a green background with a black dotted border.
    
    

    But the most useful feature is the 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.

    
        
        

    Try the above snippet by pressing enter inside TextBox1

提交回复
热议问题