S
Scott M.
Why do we need runat="server" on our <head> tags?
Scott said:Why do we need runat="server" on our <head> tags?
Scott said:Well, I understand what runat="server" means in general, but we haven't
always had that in .NET and the server never had any trouble adding tags to
the head section before.
What, specifically, does the head tag need this
for? Why does the server need to be able to access the head tag as a server
object?
Göran Andersson said:In framework 1 it didn't add anything to the head.
Yes it did said:It's only needed if you use anything that actually adds something to the
head section, like themes or the Title property.
If the head tag wouldn't be a server control, it would be in a string in a
LiteralControl object in the page. In order for the Title property to set
the title in the head, it would have to locate the LiteralControl
containing the head tag and parse the string to find out which part of the
string contained the head tag, and if it aleady contained a title tag or
not.
Scott said:I'm sorry, but your responses don't seem to reall explain why this is needed
Scott M. said:It's not about believing you. You just haven't provided an ansswer that
explains anything. You're answer is that it is needed to be able to add
things into the head section and since we've been able to do that since
.NET 1.0 (and even classic ASP), I don't see how that can be the case.
You may well be right, but I'm looking for an answer that explains why it
is needed now, since it wasn't before.
Scott said:Place this: <%="<meta name='keywords' content='one,two,three' />"%> in
between the opening and closing head tags and you get a meta tag. Not to
mention, that since most IDE's have been generating custom meta tags (with
the code generator flagged in the tag) for years, I'm having trouble
understanding why we need runat="server" to get at an area that IDE's have
always been able to get to.
Scott M. said:It's not about believing you. You just haven't provided an ansswer that
explains anything. You're answer is that it is needed to be able to add
things into the head section and since we've been able to do that since
.NET 1.0 (and even classic ASP), I don't see how that can be the case.
You may well be right, but I'm looking for an answer that explains why it
is needed now, since it wasn't before.
George said:Allow me to jump in here with my 2 cents..
Starting .NET 2.0 @Page directive has a Title property (Page class has a
Title property).
Try to set it with out having <head runat=server>... You will get an
error.. Also read documentation on Page.Title
"Use the Title property to set the page title in the HTML header sent to
the requesting browser.
Note The page must contain a <head> element with the attribute
runat="server", otherwise the title will not render."
PS: If you are not using Title property in your project then you
(probably) do not need to have <head runat=server>
George.
George said:YES and again if you are no using it then you do not need <head
runat=server>.
The Title property makes sense when used in conjunction with MasterPages.
When <HEAD> tag is in the MasterPage and each page needs to set custom
Title (Good for Google/Yahoo). So that was a Microsoft's way to let
developers do it (set custom title on page).
George.
Scott said:You miss my point. Call it what you want, but I am able to gain access to
the content that will be rendered in the head section without
runat="server". So, my question still stands: What does runat="server" in
the head tag buy me that I didn't have before it?
Scott said:I am quite sure that I am and I'm quite sure that you aren't explaining it
in a way that makes me get the point.
All you are saying is that it is requires so that content can be placed in
the head secation and I'm telling you that this can be done without
runat="server".
block inside the head tag, but that requires you to know where the head
tag is already. That can't be done automatically.
Scott said:The way that you demonstated is to put a server control or an inline code
block inside the head tag, but that requires you to know where the head
tag is already. That can't be done automatically.
[sigh] Yes it can, it's been done for years by every HTML editor that wanted
to insert a <meta name="Generator" ...> tag into the output.