I’m really new to ASP.NET. I was just checking out a default ASP.NET web application. It comes by default with a few pages (Default.aspx, About.aspx etc).
I noticed that the Site.master file is the file where i create the main layout for my pages.
But i also noticed that the head tag has a runat="server" attribute.
I know this tag is used in <asp:XXX> tags, but why in a <head> tag???
Also, when i remove that attribute, then all of the styles are gone from the webpage. So appearently it’s doing something. I just don’t understand what its exactly doing…
So why is it there, on an HTML tag…??? I don’t see any code in there that should be run on the server…
<head runat="server">
<title>Hallo</title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<!-- This part is run on the server. So why does the head tag
also need a runat=server ?? -->
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
The head element contains a
runat="server"attribute, which indicates that it is a server control (rather than static HTML). All ASP.NET pages derive from the Page class, which is located in the System.Web.UI namespace. This class contains a Header property that provides access to the page’s region. Using the Header property we can set an ASP.NET page’s title or add additional markup to the rendered section. It is possible, then, to customize a content page’s element by writing a bit of code in the page’sPage_Loadevent handler.For more info see Specifying Meta Tags in ASP.NET with VB.NET.