Connecting Tech Pros Worldwide Help | Site Map

Setting Doctype from codebehind ?

WT
Guest
 
Posts: n/a
#1: Jun 27 '08
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

Alexey Smirnov
Guest
 
Posts: n/a
#2: Jun 27 '08

re: Setting Doctype from codebehind ?


On May 16, 12:57*pm, "WT" <W...@newsgroups.nospamwrote:
Quote:
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.n...tml.php?page=2
Steven Cheng [MSFT]
Guest
 
Posts: n/a
#3: Jun 27 '08

re: Setting Doctype from codebehind ?


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:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.






--------------------
Quote:
>From: "WT" <WT@newsgroups.nospam>
>Subject: Setting Doctype from codebehind ?
>Date: Fri, 16 May 2008 12:57:02 +0200
Quote:
>
>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
Guest
 
Posts: n/a
#4: Jun 27 '08

re: Setting Doctype from codebehind ?


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]" <stcheng@online.microsoft.coma écrit dans le message
de news:6b%23DvAWuIHA.5796@TK2MSFTNGHUB02.phx.gbl...
Quote:
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:
msdnmg@microsoft.com.
>
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
>
>
>
>
>
>
--------------------
Quote:
>>From: "WT" <WT@newsgroups.nospam>
>>Subject: Setting Doctype from codebehind ?
>>Date: Fri, 16 May 2008 12:57:02 +0200
>
Quote:
>>
>>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
Guest
 
Posts: n/a
#5: Jun 27 '08

re: Setting Doctype from codebehind ?


Thanks Alexey,

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

"Alexey Smirnov" <alexey.smirnov@gmail.coma écrit dans le message de
news:712a08f6-41a4-4754-8367-92b6a74c8924@m73g2000hsh.googlegroups.com...
On May 16, 12:57 pm, "WT" <W...@newsgroups.nospamwrote:
Quote:
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.n...tml.php?page=2

Steven Cheng [MSFT]
Guest
 
Posts: n/a
#6: Jun 27 '08

re: Setting Doctype from codebehind ?


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:
msdnmg@microsoft.com.

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

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

--------------------
Quote:
>From: "WT" <WT@newsgroups.nospam>
>References: <F6455E5F-812C-4EAF-B197-6EEEF1797EA0@microsoft.com>
<6b#DvAWuIHA.5796@TK2MSFTNGHUB02.phx.gbl>
Quote:
>In-Reply-To: <6b#DvAWuIHA.5796@TK2MSFTNGHUB02.phx.gbl>
>Subject: Re: Setting Doctype from codebehind ?
>Date: Mon, 19 May 2008 14:41:25 +0200
Quote:
>
>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
Quote:
>to a std aspx page.
>
>Thanks again.
>CS
>
>
>
>"Steven Cheng [MSFT]" <stcheng@online.microsoft.coma écrit dans le
message
Quote:
>de news:6b%23DvAWuIHA.5796@TK2MSFTNGHUB02.phx.gbl...
Quote:
>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
Quote:
Quote:
>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:
>msdnmg@microsoft.com.
>>
>================================================= =
>Get notification to my posts through email? Please refer to
>>
http://msdn.microsoft.com/subscripti...ult.aspx#notif
Quote:
Quote:
>ications.
>>
>Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
Quote:
Quote:
>where an initial response from the community or a Microsoft Support
>Engineer within 1 business day is acceptable. Please note that each
follow
Quote:
Quote:
>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/subscripti...t/default.aspx.
>================================================= =
>This posting is provided "AS IS" with no warranties, and confers no
>rights.
>>
>>
>>
>>
>>
>>
>--------------------
Quote:
>>>From: "WT" <WT@newsgroups.nospam>
>>>Subject: Setting Doctype from codebehind ?
>>>Date: Fri, 16 May 2008 12:57:02 +0200
>>
Quote:
>>>
>>>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
Quote:
Quote:
Quote:
>>>any Doctype or html tags in the page ?
>>>
>>>Thanks
>>>CS
>>>
>>>
>>
>
>
Alexey Smirnov
Guest
 
Posts: n/a
#7: Jun 27 '08

re: Setting Doctype from codebehind ?


On May 20, 4:59*am, stch...@online.microsoft.com (Steven Cheng [MSFT])
wrote:
Quote:
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:
msd...@microsoft.com.
>
==================================================
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" <W...@newsgroups.nospam>
Quote:
References: <F6455E5F-812C-4EAF-B197-6EEEF1797...@microsoft.com>
>
<6b#DvAWuIHA.5...@TK2MSFTNGHUB02.phx.gbl>
>
>
>
>
>
Quote:
In-Reply-To: <6b#DvAWuIHA.5...@TK2MSFTNGHUB02.phx.gbl>
Subject: Re: Setting Doctype from codebehind ?
Date: Mon, 19 May 2008 14:41:25 +0200
>
Quote:
Hi Steven,
>
Quote:
Thanks, your solution seems good.
Do you know a way to detect in codebehind if DocType is set or not in the
current aspx ?
>
Quote:
For subs question, Yes I am doing a Server.Transfer from a std
Default.aspx
Quote:
to a std aspx page.
>
Quote:
Thanks again.
CS
>
Quote:
"Steven Cheng [MSFT]" <stch...@online.microsoft.coma écrit dans le
message
Quote:
denews:6b%23DvAWuIHA.5796@TK2MSFTNGHUB02.phx.gbl.. .
Quote:
Hi CS,
>
Quote:
Quote:
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.
>
Quote:
Quote:
=========aspx===============
<%@ Page Language="C#" AutoEventWireup="true" *CodeFile="Default.aspx.cs"
Inherits="_Default" %>
>
Quote:
Quote:
<asp:literal runat="server" id="dt"></asp:literal>
>
Quote:
Quote:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
>
Quote:
Quote:
==============code behind=========
>
Quote:
Quote:
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\">";
>
Quote:
Quote:
}
======================
>
Quote:
Quote:
Alexey also provided an article which mentioned overriding pages' render
method to write the doctype(or any other output content).
>
Quote:
Quote:
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?
>
Quote:
Quote:
Sincerely,
>
Quote:
Quote:
Steven Cheng
>
Quote:
Quote:
Microsoft MSDN Online Support Lead
>
Quote:
Quote:
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
Quote:
Quote:
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:
msd...@microsoft.com.
>
Quote:
Quote:
==================================================
Get notification to my posts through email? Please refer to
>
http://msdn.microsoft.com/subscripti...ps/default.asp...
>
>
>
Quote:
Quote:
ications.
>
Quote:
Quote:
Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
Quote:
Quote:
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
Quote:
Quote:
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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
>
Quote:
Quote:
--------------------
>>From: "WT" <W...@newsgroups.nospam>
>>Subject: Setting Doctype from codebehind ?
>>Date: Fri, 16 May 2008 12:57:02 +0200
>
Quote:
Quote:
>>Hello,
>
Quote:
Quote:
>>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
Quote:
Quote:
>>any Doctype or html tags in the page ?
>
Quote:
Quote:
>>Thanks
>>CS- Hide quoted text -
>
- Show quoted text -- Hide quoted text -
>
- Show quoted text -
I agree with Steven
Closed Thread