<head runat="server">

Discussion in 'ASP .Net' started by Scott M., Sep 5, 2008.

  1. Scott M.

    Scott M. Guest

    Why do we need runat="server" on our <head> tags?
    Scott M., Sep 5, 2008
    #1
    1. Advertising

  2. Scott M. wrote:
    > Why do we need runat="server" on our <head> tags?
    >


    So that the head tag will be parsed into a server control, so that the
    server code can access it.

    Without the attribute the tag would just be treated like literal text,
    and the server code could not easily add tags inside the head tag.

    --
    Göran Andersson
    _____
    http://www.guffa.com
    Göran Andersson, Sep 5, 2008
    #2
    1. Advertising

  3. Scott M.

    Scott M. Guest

    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" <> wrote in message
    news:ulS$...
    > Scott M. wrote:
    >> Why do we need runat="server" on our <head> tags?

    >
    > So that the head tag will be parsed into a server control, so that the
    > server code can access it.
    >
    > Without the attribute the tag would just be treated like literal text, and
    > the server code could not easily add tags inside the head tag.
    >
    > --
    > Göran Andersson
    > _____
    > http://www.guffa.com
    Scott M., Sep 6, 2008
    #3
  4. Scott M. wrote:
    > 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.


    In framework 1 it didn't add anything to the head.

    > 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?


    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.

    >
    > "Göran Andersson" <> wrote in message
    > news:ulS$...
    >> Scott M. wrote:
    >>> Why do we need runat="server" on our <head> tags?

    >> So that the head tag will be parsed into a server control, so that the
    >> server code can access it.
    >>
    >> Without the attribute the tag would just be treated like literal text, and
    >> the server code could not easily add tags inside the head tag.
    >>
    >> --
    >> Göran Andersson
    >> _____
    >> http://www.guffa.com

    >
    >



    --
    Göran Andersson
    _____
    http://www.guffa.com
    Göran Andersson, Sep 6, 2008
    #4
  5. Scott M.

    Scott M. Guest

    "Göran Andersson" <> wrote in message
    news:...
    > Scott M. wrote:
    >> 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.

    >
    > In framework 1 it didn't add anything to the head.


    Yes it did, it added <meta> tags.

    >
    >> 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?

    >
    > It's only needed if you use anything that actually adds something to the
    > head section, like themes or the Title property.


    Uh no. We've been able to modify the page titile without the runat="server".

    >
    > 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.


    If the title tag needs to be accesses via the sever, then why not just add
    runat="server" to the title tag? As far as being able to add any
    informaiton into the head section, you don't need runat="server" to do that.
    You could simply place a literal contrin somewhere inside the head section.

    I'm sorry, but your responses don't seem to reall explain why this is needed
    since everything you've said it's for has been accomplished without it for
    years. Adding runat="server" makes that particular element programmable at
    the server. Why would I need/want to program the head tag at the server?
    Obviously, someone at Microsoft feels that this is so important that all VS
    2008 generated pages get the head tag marked with this attribute.

    -Scott

    >
    >>
    >> "Göran Andersson" <> wrote in message
    >> news:ulS$...
    >>> Scott M. wrote:
    >>>> Why do we need runat="server" on our <head> tags?
    >>> So that the head tag will be parsed into a server control, so that the
    >>> server code can access it.
    >>>
    >>> Without the attribute the tag would just be treated like literal text,
    >>> and the server code could not easily add tags inside the head tag.
    >>>
    >>> --
    >>> Göran Andersson
    >>> _____
    >>> http://www.guffa.com

    >>
    >>

    >
    >
    > --
    > Göran Andersson
    > _____
    > http://www.guffa.com
    Scott M., Sep 6, 2008
    #5
  6. Scott M. wrote:
    > I'm sorry, but your responses don't seem to reall explain why this is needed


    Well, I tried to explain, but if you choose not to believe me you can
    just... well... whatever...

    --
    Göran Andersson
    _____
    http://www.guffa.com
    Göran Andersson, Sep 6, 2008
    #6
  7. Scott M.

    Scott M. Guest

    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.


    "Göran Andersson" <> wrote in message
    news:...
    > Scott M. wrote:
    >> I'm sorry, but your responses don't seem to reall explain why this is
    >> needed

    >
    > Well, I tried to explain, but if you choose not to believe me you can
    > just... well... whatever...
    >
    > --
    > Göran Andersson
    > _____
    > http://www.guffa.com
    Scott M., Sep 6, 2008
    #7
  8. "Scott M." <> wrote in message
    news:...
    > 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.
    >


    Can you post a chunk of ASP.NET 1.1 that does what you mean?

    Your comment that 'even classic ASP' could do it seems to indicate that
    there is a misunderstanding in this thread. Code usually helps clear things
    up. (I prefer to speak in VB or C# myself rather English, less likely to be
    mis-interpreted ;)

    --
    Anthony Jones - MVP ASP/ASP.NET
    Anthony Jones, Sep 6, 2008
    #8
  9. Scott M.

    Scott M. Guest

    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.





    "Anthony Jones" <> wrote in message
    news:%...
    > "Scott M." <> wrote in message
    > news:...
    >> 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.
    >>

    >
    > Can you post a chunk of ASP.NET 1.1 that does what you mean?
    >
    > Your comment that 'even classic ASP' could do it seems to indicate that
    > there is a misunderstanding in this thread. Code usually helps clear
    > things up. (I prefer to speak in VB or C# myself rather English, less
    > likely to be mis-interpreted ;)
    >
    > --
    > Anthony Jones - MVP ASP/ASP.NET
    >
    Scott M., Sep 6, 2008
    #9
  10. Scott M. wrote:
    > 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.
    >


    That's not specifically adding a meta tag in the head tag, that is just
    adding a literal string among other literal strings.

    If you want to create all the response as string literals, you don't
    need any server controls at all.

    --
    Göran Andersson
    _____
    http://www.guffa.com
    Göran Andersson, Sep 6, 2008
    #10
  11. Scott M.

    George Guest

    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.






    "Scott M." <> wrote in message
    news:...
    > 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.
    >
    >
    > "Göran Andersson" <> wrote in message
    > news:...
    >> Scott M. wrote:
    >>> I'm sorry, but your responses don't seem to reall explain why this is
    >>> needed

    >>
    >> Well, I tried to explain, but if you choose not to believe me you can
    >> just... well... whatever...
    >>
    >> --
    >> Göran Andersson
    >> _____
    >> http://www.guffa.com

    >
    >
    George, Sep 6, 2008
    #11
  12. Scott M.

    Scott M. Guest

    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?


    "Göran Andersson" <> wrote in message
    news:%...
    > Scott M. wrote:
    >> 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.
    >>

    >
    > That's not specifically adding a meta tag in the head tag, that is just
    > adding a literal string among other literal strings.
    >
    > If you want to create all the response as string literals, you don't need
    > any server controls at all.
    >
    > --
    > Göran Andersson
    > _____
    > http://www.guffa.com
    Scott M., Sep 6, 2008
    #12
  13. Scott M.

    Scott M. Guest

    So is the ability to use the @Page Title directive the only thing that
    adding runat="server" to the head tag buys me?


    "George" <> wrote in message
    news:...
    > 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.
    >
    >
    >
    >
    >
    >
    > "Scott M." <> wrote in message
    > news:...
    >> 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.
    >>
    >>
    >> "Göran Andersson" <> wrote in message
    >> news:...
    >>> Scott M. wrote:
    >>>> I'm sorry, but your responses don't seem to reall explain why this is
    >>>> needed
    >>>
    >>> Well, I tried to explain, but if you choose not to believe me you can
    >>> just... well... whatever...
    >>>
    >>> --
    >>> Göran Andersson
    >>> _____
    >>> http://www.guffa.com

    >>
    >>

    >
    Scott M., Sep 6, 2008
    #13
  14. Scott M.

    George Guest

    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 M." <> wrote in message
    news:%...
    > So is the ability to use the @Page Title directive the only thing that
    > adding runat="server" to the head tag buys me?
    >
    >
    > "George" <> wrote in message
    > news:...
    >> 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.
    >>
    >>
    >>
    >>
    >>
    >>
    >> "Scott M." <> wrote in message
    >> news:...
    >>> 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.
    >>>
    >>>
    >>> "Göran Andersson" <> wrote in message
    >>> news:...
    >>>> Scott M. wrote:
    >>>>> I'm sorry, but your responses don't seem to reall explain why this is
    >>>>> needed
    >>>>
    >>>> Well, I tried to explain, but if you choose not to believe me you can
    >>>> just... well... whatever...
    >>>>
    >>>> --
    >>>> Göran Andersson
    >>>> _____
    >>>> http://www.guffa.com
    >>>
    >>>

    >>

    >
    >
    George, Sep 7, 2008
    #14
  15. Scott M.

    Scott M. Guest

    Thank you very much!


    "George" <> wrote in message
    news:OSD%...
    > 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 M." <> wrote in message
    > news:%...
    >> So is the ability to use the @Page Title directive the only thing that
    >> adding runat="server" to the head tag buys me?
    >>
    >>
    >> "George" <> wrote in message
    >> news:...
    >>> 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.
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> "Scott M." <> wrote in message
    >>> news:...
    >>>> 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.
    >>>>
    >>>>
    >>>> "Göran Andersson" <> wrote in message
    >>>> news:...
    >>>>> Scott M. wrote:
    >>>>>> I'm sorry, but your responses don't seem to reall explain why this is
    >>>>>> needed
    >>>>>
    >>>>> Well, I tried to explain, but if you choose not to believe me you can
    >>>>> just... well... whatever...
    >>>>>
    >>>>> --
    >>>>> Göran Andersson
    >>>>> _____
    >>>>> http://www.guffa.com
    >>>>
    >>>>
    >>>

    >>
    >>

    >
    Scott M., Sep 7, 2008
    #15
  16. Scott M. wrote:
    > 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?


    No, it's you who are missing the point.

    You can add content in the actual head, not just in a container that you
    have placed in the head.

    This is required to use any built in features, like themes, that need to
    put code in the head.

    If you get an error message that tells you that runat="server" is
    required in the head tag, it's because you are using some of the built
    in fetures that needs to put code in the head. The error message also
    tells you exactly what it is that you are using, so if you don't want to
    use that featue, you don't net to put runat="server" in the head tag.

    --
    Göran Andersson
    _____
    http://www.guffa.com
    Göran Andersson, Sep 7, 2008
    #16
  17. Scott M.

    Scott M. Guest

    > No, it's you who are missing the point.

    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".

    Anyway, thanks for trying.
    Scott M., Sep 7, 2008
    #17
  18. Scott M. wrote:
    >> No, it's you who are missing the point.

    >
    > 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".


    Yes, of course it's possible, but far from practical.

    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.

    Another alternative is to loop through all the literal controls in the
    page to locate the head tag. Then the string containing the head tag
    could be parsed so that the string could be modified. Although possible,
    it would be doing exactly what's done when you put runat="server" in the
    head tag, only over and over again every time the header needed
    modifying. The mechanism for parsing the code already exists, there is
    no reason to do it in a different way for the head tag.

    >
    > Anyway, thanks for trying.
    >


    --
    Göran Andersson
    _____
    http://www.guffa.com
    Göran Andersson, Sep 7, 2008
    #18
  19. Scott M.

    Scott M. Guest

    > 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.
    Scott M., Sep 7, 2008
    #19
  20. Scott M. wrote:
    >> 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.
    >


    [sigh] Yes, as I said, it's possible. It can be done, but it would be
    stupid. It doesn't make sense to parse the code one extra time to find
    the head tag, when the code has already been parsed once.

    --
    Göran Andersson
    _____
    http://www.guffa.com
    Göran Andersson, Sep 8, 2008
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lloyd Dupont
    Replies:
    2
    Views:
    2,942
    Lloyd Dupont
    Sep 22, 2004
  2. =?Utf-8?B?VG9t?=

    DynamicHoverStyle Bug w/<head runat="server" />

    =?Utf-8?B?VG9t?=, Jun 22, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    458
    =?Utf-8?B?VG9t?=
    Jun 22, 2006
  3. Christopher
    Replies:
    0
    Views:
    438
    Christopher
    Mar 22, 2008
  4. Christopher

    Disable head runat=server for some pages?

    Christopher, Mar 26, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    419
    Christopher
    Mar 26, 2008
  5. Anonymous

    <head runat="server">

    Anonymous, Feb 9, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    338
    Mark Fitzpatrick
    Feb 14, 2009
Loading...

Share This Page