Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working on a website I am confused with the following,

What is the main difference between
<body>.....</body>
and
<body runat="server">...</body> 

and in which situations which one is better. Is there any benefit if i put runat="server"

For server controls we will add attribute runat="server". Why we use it for body tag.
Posted
Updated 5-Jul-12 0:50am
v4

runat="sever" means it is the ability to take a "normal" client-side HTML control and "upgrade" it to a server control; and giving it an id is primarily there to migrate older non-ASP .NET application to ASP .NET.
 
Share this answer
 
v2
Comments
Manas Bhardwaj 5-Jul-12 6:41am    
correct +5
Prasad_Kulkarni 5-Jul-12 6:44am    
Thank you Manas!
Any element marked with runat="server" lets the framework know that this will be a control on the server side. This article has more details:

http://www.drdobbs.com/exploring-the-runat-attribute/184416787[^]
 
Share this answer
 
Comments
Prasad_Kulkarni 5-Jul-12 6:44am    
My 5!
Not all controls included within the body tag may be run at server.

Based on your question, this blog[^] makes an interesting read.
 
Share this answer
 
Comments
Manas Bhardwaj 5-Jul-12 6:42am    
Right +5
Abhinav S 5-Jul-12 6:43am    
Thanks.
Prasad_Kulkarni 5-Jul-12 6:44am    
Good reference +5!
Abhinav S 5-Jul-12 6:45am    
Thank you.
Srinubabu Ravilla 5-Jul-12 6:56am    
Nice reference thank you sir.....
Hi,
If you are using Master Pages in an ASP.NET application and you need to add an attribute to the <BODY> tag from a Content Page -- for instance, to set a client script function for the onload event of the page -- you will find that you can't do it directly because the <BODY> tag is in the Master Page, not in your Content Page.
Here you go:
Adding attributes to the <body> tag when using Master Pages[^]

All the best.
--Amit
 
Share this answer
 
runat="sever" means it is the ability to take a "normal" client-side HTML control and "upgrade" it to a server control
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900