Setting Doctype from codebehind ?

W

WT

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
 
S

Steven Cheng [MSFT]

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:
(e-mail address removed).

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






--------------------
 
W

WT

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
 
W

WT

Thanks Alexey,

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

"Anon User" <> a écrit dans le message de
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
 
S

Steven Cheng [MSFT]

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:
(e-mail address removed).

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

--------------------
In-Reply-To: <6b#[email protected]>
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]" <[email protected]> a écrit dans le message
de news:6b%[email protected]...
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:
(e-mail address removed).

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

Guest

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:
(e-mail address removed).

==================================================
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 said:
References: <[email protected]>
<6b#[email protected]>





In-Reply-To: <6b#[email protected]>
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]" <[email protected]> a écrit dans le message
deHi 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:
(e-mail address removed).
==================================================
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" <[email protected]>
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top