tags:

views:

49

answers:

3

I want to know what is difference between Panel control in asp.net and div with runat="server"? Since both render in div.And i want to know which one is best (conditions)?

+4  A: 

Panel and <div> are the same thing in HTML. The difference is that a Panel is a web control, and it makes it easier to access the control's method and properties in the code-behind. Making a <div> runat server also allows you to access the properties in the code-behind, but not as much compare to a Panel web control.

A Panel control requires more processing to generate HTML, while a <div> requires less. Which one should you use depends how much of the properties do you need to access in the code-behind. In general, I like to stick with plain HTML or HTML controls because they require less processing on the server, and makes the page load smaller because they don't use the viewstate.

Pandiya Chendur
I don't think there is any noticeable difference in processing time. Since both Panel and `<div runat='server'/>` are rendered by asp.net controls. Div is rendered using `HtmlGenericControl`, which has same RenderBeginTag,RenderEndTag and etc. methods. Also both Panel and Div can use ViewState.
Kirill Muzykov
+1  A: 

The code

<asp:Panel id="abc" runat="server">

is exactly the same as if you do:

<div id="abc" runat="server">

They render the same, but it's the functionality with other WebControls that the Panel is most used, and the Panel web control gives you more control under code-behind as it exposes more properties.

balexandre