Setting Doctype from codebehind ?

Discussion in 'ASP .Net' started by WT, May 16, 2008.

  1. WT

    WT Guest

    Hello,

    I am searching for a way to generate automatically from codebehind the
    <!Doctype....> for asp.net pages using .net 3.5 c# and vs2008.
    Subidiary question: if I do a server transfert in my codebehind, do I need
    any Doctype or html tags in the page ?

    Thanks
    CS
     
    WT, May 16, 2008
    #1
    1. Advertising

  2. On May 16, 12:57 pm, "WT" <> wrote:
    > Hello,
    >
    > I am searching for a way to generate automatically from codebehind the
    > <!Doctype....> for asp.net pages using .net 3.5 c# and vs2008.
    > Subidiary question: if I do a server transfert in my codebehind, do I need
    > any Doctype or html tags in the page ?
    >
    > Thanks
    > CS


    You can override the Render method to put new Doctype to the output

    Here's an example
    http://www.asp-php.net/scripts/asp.net/aspnet-xhtml.php?page=2
     
    Alexey Smirnov, May 18, 2008
    #2
    1. Advertising

  3. Hi CS,

    As for the DocType, a simple way to set it via codebehind is declare an
    ASP.NET LIteral control in aspx template so that you can assign the doc
    type string via Literal control's Text property e.g.


    =========aspx===============
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
    Inherits="_Default" %>


    <asp:literal runat="server" id="dt"></asp:literal>


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">

    ==============code behind=========

    protected void Page_Load(object sender, EventArgs e)
    {
    this.dt.Text= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
    Transitional//EN\"
    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";

    }
    ======================

    Alexey also provided an article which mentioned overriding pages' render
    method to write the doctype(or any other output content).

    For the subidiary question " if I do a server transfert in my codebehind,
    do I need any Doctype or html tags in the page ?", I'm not very sure what
    is the exact things you want to do, would you provide some further
    description on this? Are you performing some server-side redirection like
    Server.Transfer?

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.






    --------------------
    >From: "WT" <>
    >Subject: Setting Doctype from codebehind ?
    >Date: Fri, 16 May 2008 12:57:02 +0200


    >
    >Hello,
    >
    >I am searching for a way to generate automatically from codebehind the
    ><!Doctype....> for asp.net pages using .net 3.5 c# and vs2008.
    >Subidiary question: if I do a server transfert in my codebehind, do I need
    >any Doctype or html tags in the page ?
    >
    >Thanks
    >CS
    >
    >
     
    Steven Cheng [MSFT], May 19, 2008
    #3
  4. WT

    WT Guest

    Hi Steven,

    Thanks, your solution seems good.
    Do you know a way to detect in codebehind if DocType is set or not in the
    current aspx ?

    For subs question, Yes I am doing a Server.Transfer from a std Default.aspx
    to a std aspx page.

    Thanks again.
    CS



    "Steven Cheng [MSFT]" <> a écrit dans le message
    de news:6b%...
    > Hi CS,
    >
    > As for the DocType, a simple way to set it via codebehind is declare an
    > ASP.NET LIteral control in aspx template so that you can assign the doc
    > type string via Literal control's Text property e.g.
    >
    >
    > =========aspx===============
    > <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
    > Inherits="_Default" %>
    >
    >
    > <asp:literal runat="server" id="dt"></asp:literal>
    >
    >
    > <html xmlns="http://www.w3.org/1999/xhtml">
    > <head runat="server">
    >
    > ==============code behind=========
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > this.dt.Text= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
    > Transitional//EN\"
    > \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
    >
    > }
    > ======================
    >
    > Alexey also provided an article which mentioned overriding pages' render
    > method to write the doctype(or any other output content).
    >
    > For the subidiary question " if I do a server transfert in my codebehind,
    > do I need any Doctype or html tags in the page ?", I'm not very sure what
    > is the exact things you want to do, would you provide some further
    > description on this? Are you performing some server-side redirection like
    > Server.Transfer?
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    > Delighting our customers is our #1 priority. We welcome your comments and
    > suggestions about how we can improve the support we provide to you. Please
    > feel free to let my manager know what you think of the level of service
    > provided. You can send feedback directly to my manager at:
    > .
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications.
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    > ==================================================
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    >
    >
    >
    >
    >
    > --------------------
    >>From: "WT" <>
    >>Subject: Setting Doctype from codebehind ?
    >>Date: Fri, 16 May 2008 12:57:02 +0200

    >
    >>
    >>Hello,
    >>
    >>I am searching for a way to generate automatically from codebehind the
    >><!Doctype....> for asp.net pages using .net 3.5 c# and vs2008.
    >>Subidiary question: if I do a server transfert in my codebehind, do I need
    >>any Doctype or html tags in the page ?
    >>
    >>Thanks
    >>CS
    >>
    >>

    >
     
    WT, May 19, 2008
    #4
  5. WT

    WT Guest

    Thanks Alexey,

    And do yo know a way to detect id Doctype is missing or not before the
    Render Method ?
    CS

    "Alexey Smirnov" <> a écrit dans le message de
    news:...
    On May 16, 12:57 pm, "WT" <> wrote:
    > Hello,
    >
    > I am searching for a way to generate automatically from codebehind the
    > <!Doctype....> for asp.net pages using .net 3.5 c# and vs2008.
    > Subidiary question: if I do a server transfert in my codebehind, do I need
    > any Doctype or html tags in the page ?
    >
    > Thanks
    > CS


    You can override the Render method to put new Doctype to the output

    Here's an example
    http://www.asp-php.net/scripts/asp.net/aspnet-xhtml.php?page=2
     
    WT, May 19, 2008
    #5
  6. Thanks for your reply CS,

    If you just do the Server.Transfer, the new page will got through all the
    page processing stages and if Doctype originally exists, it will also be
    rendered.

    For the new question about "how to detect if Doctype exists before render",
    I think this is quite limited because the DocType is only stored in aspx
    template file which is loaded the rendering stage.

    I have performed some further test on this. Actually, for the "DocType"
    section, the ASP.NET page will generate an Literalcontrol which used to
    contains the html at the begining of the aspx template file. However, the
    LiteralControl's Text content is not populated before rendering(I've tried
    access it and print its content). therefore, I think so far for
    manipulating doctype, the following approaches should be the reasonable
    ones:

    ** manually put a Literal control in page template to set the doctype

    ** use Render method to manipulate it.

    If you have any other consideration, welcome to post here.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.

    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    >From: "WT" <>
    >References: <>

    <6b#>
    >In-Reply-To: <6b#>
    >Subject: Re: Setting Doctype from codebehind ?
    >Date: Mon, 19 May 2008 14:41:25 +0200


    >
    >Hi Steven,
    >
    >Thanks, your solution seems good.
    >Do you know a way to detect in codebehind if DocType is set or not in the
    >current aspx ?
    >
    >For subs question, Yes I am doing a Server.Transfer from a std

    Default.aspx
    >to a std aspx page.
    >
    >Thanks again.
    >CS
    >
    >
    >
    >"Steven Cheng [MSFT]" <> a écrit dans le

    message
    >de news:6b%...
    >> Hi CS,
    >>
    >> As for the DocType, a simple way to set it via codebehind is declare an
    >> ASP.NET LIteral control in aspx template so that you can assign the doc
    >> type string via Literal control's Text property e.g.
    >>
    >>
    >> =========aspx===============
    >> <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
    >> Inherits="_Default" %>
    >>
    >>
    >> <asp:literal runat="server" id="dt"></asp:literal>
    >>
    >>
    >> <html xmlns="http://www.w3.org/1999/xhtml">
    >> <head runat="server">
    >>
    >> ==============code behind=========
    >>
    >> protected void Page_Load(object sender, EventArgs e)
    >> {
    >> this.dt.Text= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
    >> Transitional//EN\"
    >> \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
    >>
    >> }
    >> ======================
    >>
    >> Alexey also provided an article which mentioned overriding pages' render
    >> method to write the doctype(or any other output content).
    >>
    >> For the subidiary question " if I do a server transfert in my codebehind,
    >> do I need any Doctype or html tags in the page ?", I'm not very sure what
    >> is the exact things you want to do, would you provide some further
    >> description on this? Are you performing some server-side redirection like
    >> Server.Transfer?
    >>
    >> Sincerely,
    >>
    >> Steven Cheng
    >>
    >> Microsoft MSDN Online Support Lead
    >>
    >>
    >> Delighting our customers is our #1 priority. We welcome your comments and
    >> suggestions about how we can improve the support we provide to you.

    Please
    >> feel free to let my manager know what you think of the level of service
    >> provided. You can send feedback directly to my manager at:
    >> .
    >>
    >> ==================================================
    >> Get notification to my posts through email? Please refer to
    >>

    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    >> ications.
    >>
    >> Note: The MSDN Managed Newsgroup support offering is for non-urgent

    issues
    >> where an initial response from the community or a Microsoft Support
    >> Engineer within 1 business day is acceptable. Please note that each

    follow
    >> up response may take approximately 2 business days as the support
    >> professional working with you may need further investigation to reach the
    >> most efficient resolution. The offering is not appropriate for situations
    >> that require urgent, real-time or phone-based interactions or complex
    >> project analysis and dump analysis issues. Issues of this nature are best
    >> handled working with a dedicated Microsoft Support Engineer by contacting
    >> Microsoft Customer Support Services (CSS) at
    >> http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >> ==================================================
    >> This posting is provided "AS IS" with no warranties, and confers no
    >> rights.
    >>
    >>
    >>
    >>
    >>
    >>
    >> --------------------
    >>>From: "WT" <>
    >>>Subject: Setting Doctype from codebehind ?
    >>>Date: Fri, 16 May 2008 12:57:02 +0200

    >>
    >>>
    >>>Hello,
    >>>
    >>>I am searching for a way to generate automatically from codebehind the
    >>><!Doctype....> for asp.net pages using .net 3.5 c# and vs2008.
    >>>Subidiary question: if I do a server transfert in my codebehind, do I

    need
    >>>any Doctype or html tags in the page ?
    >>>
    >>>Thanks
    >>>CS
    >>>
    >>>

    >>

    >
    >
     
    Steven Cheng [MSFT], May 20, 2008
    #6
  7. On May 20, 4:59 am, (Steven Cheng [MSFT])
    wrote:
    > Thanks for your reply CS,
    >
    > If you just do the Server.Transfer, the new page will got through all the
    > page processing stages and if Doctype originally exists, it will also be
    > rendered.
    >
    > For the new question about "how to detect if Doctype exists before render",
    > I think this is quite limited because the DocType is only stored in aspx
    > template file which is loaded the rendering stage.  
    >
    > I have performed some further test on this. Actually, for the "DocType"
    > section, the ASP.NET page will generate an Literalcontrol which used to
    > contains the html at the begining of the aspx template file.  However, the
    > LiteralControl's Text content is not populated before rendering(I've tried
    > access it and print its content).  therefore, I think so far for
    > manipulating doctype, the following approaches should be the reasonable
    > ones:
    >
    > ** manually put a Literal control in page template to set the doctype
    >
    > ** use Render method to manipulate it.
    >
    > If you have any other consideration, welcome to post here.
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    > Delighting our customers is our #1 priority. We welcome your comments and
    > suggestions about how we can improve the support we provide to you. Please
    > feel free to let my manager know what you think of the level of service
    > provided. You can send feedback directly to my manager at:
    > .
    >
    > ==================================================
    > Get notification to my posts through email? Please refer tohttp://msdn.microsoft.com/subscriptions/managednewsgroups/default.asp...
    > ications.
    >
    > ==================================================
    > This posting is provided "AS IS" with no warranties, and confers no rights..
    >
    > -------------------->From: "WT" <>
    > >References: <>

    >
    > <6b#>
    >
    >
    >
    >
    >
    > >In-Reply-To: <6b#>
    > >Subject: Re: Setting Doctype from codebehind ?
    > >Date: Mon, 19 May 2008 14:41:25 +0200

    >
    > >Hi Steven,

    >
    > >Thanks, your solution seems good.
    > >Do you know a way to detect in codebehind if DocType is set or not in the
    > >current aspx ?

    >
    > >For subs question, Yes I am doing a Server.Transfer from a std

    > Default.aspx
    > >to a std aspx page.

    >
    > >Thanks again.
    > >CS

    >
    > >"Steven Cheng [MSFT]" <> a écrit dans le

    > message
    > >denews:6b%...
    > >> Hi CS,

    >
    > >> As for the DocType, a simple way to set it via codebehind is declare an
    > >> ASP.NET LIteral control in aspx template so that you can assign the doc
    > >> type string via Literal control's Text property e.g.

    >
    > >> =========aspx===============
    > >> <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs"
    > >> Inherits="_Default" %>

    >
    > >> <asp:literal runat="server" id="dt"></asp:literal>

    >
    > >> <html xmlns="http://www.w3.org/1999/xhtml">
    > >> <head runat="server">

    >
    > >> ==============code behind=========

    >
    > >> protected void Page_Load(object sender, EventArgs e)
    > >>    {
    > >>        this.dt.Text= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
    > >> Transitional//EN\"
    > >> \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";

    >
    > >> }
    > >> ======================

    >
    > >> Alexey also provided an article which mentioned overriding pages' render
    > >> method to write the doctype(or any other output content).

    >
    > >> For the subidiary question " if I do a server transfert in my codebehind,
    > >> do I need any Doctype or html tags in the page ?", I'm not very sure what
    > >> is the exact things you want to do, would you provide some further
    > >> description on this? Are you performing some server-side redirection like
    > >> Server.Transfer?

    >
    > >> Sincerely,

    >
    > >> Steven Cheng

    >
    > >> Microsoft MSDN Online Support Lead

    >
    > >> Delighting our customers is our #1 priority. We welcome your comments and
    > >> suggestions about how we can improve the support we provide to you.

    > Please
    > >> feel free to let my manager know what you think of the level of service
    > >> provided. You can send feedback directly to my manager at:
    > >> .

    >
    > >> ==================================================
    > >> Get notification to my posts through email? Please refer to

    >
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.asp...
    >
    >
    >
    > >> ications.

    >
    > >> Note: The MSDN Managed Newsgroup support offering is for non-urgent

    > issues
    > >> where an initial response from the community or a Microsoft Support
    > >> Engineer within 1 business day is acceptable. Please note that each

    > follow
    > >> up response may take approximately 2 business days as the support
    > >> professional working with you may need further investigation to reach the
    > >> most efficient resolution. The offering is not appropriate for situations
    > >> that require urgent, real-time or phone-based interactions or complex
    > >> project analysis and dump analysis issues. Issues of this nature are best
    > >> handled working with a dedicated Microsoft Support Engineer by contacting
    > >> Microsoft Customer Support Services (CSS) at
    > >>http://msdn.microsoft.com/subscriptions/support/default.aspx.
    > >> ==================================================
    > >> This posting is provided "AS IS" with no warranties, and confers no
    > >> rights.

    >
    > >> --------------------
    > >>>From: "WT" <>
    > >>>Subject: Setting Doctype from codebehind ?
    > >>>Date: Fri, 16 May 2008 12:57:02 +0200

    >
    > >>>Hello,

    >
    > >>>I am searching for a way to generate automatically from codebehind the
    > >>><!Doctype....> for asp.net pages using .net 3.5 c# and vs2008.
    > >>>Subidiary question: if I do a server transfert in my codebehind, do I

    > need
    > >>>any Doctype or html tags in the page ?

    >
    > >>>Thanks
    > >>>CS- Hide quoted text -

    >
    > - Show quoted text -- Hide quoted text -
    >
    > - Show quoted text -


    I agree with Steven
     
    Alexey Smirnov, May 20, 2008
    #7
    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. Kenneth Keeley

    Setting DocType in Asp.Net

    Kenneth Keeley, Jun 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    648
    Cowboy \(Gregory A. Beamer\) [MVP]
    Jun 30, 2004
  2. Michael Preminger

    Setting DOCTYPE to a DOM- document

    Michael Preminger, Dec 20, 2004, in forum: Java
    Replies:
    5
    Views:
    12,132
    John C. Bollinger
    Dec 22, 2004
  3. Replies:
    11
    Views:
    1,450
  4. danmc91
    Replies:
    3
    Views:
    465
    danmc91
    Jan 1, 2007
  5. Larry Lindstrom
    Replies:
    19
    Views:
    1,353
    Jonathan N. Little
    Jun 12, 2012
Loading...

Share This Page