English 中文(简体)
Change the doctype of an aspx page dynamically
原标题:

We use master pages in our web application, the doctype is defined in the master page.

On one of the pages I need to change the doctype, or else a third-party control renders incorrectly.

How can I change the doctype of only that certain page without affecting the rest of the pages?

问题回答

By far the simplest way is to make another copy of your master page, change the doctype in that and have this page use the new master.

I don t know if it would work but

You can reset the content type with

Response.Clear();
Response.ContentType = "text/html";

Then write your doctype type

Response.Write(<new doc-type>);

But you will also loose all meta headers and such, you re probably better off with the other solution provided by Chris Lively...

Have you used an ASP Literal control?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:literal runat="server" id="docType"></asp:literal>

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

Then in the Page_Load, you could:

this.docType.Text = {your doctype-string here};

This works too....

protected override void Render(HtmlTextWriter writer)
{
        StringBuilder sb = new StringBuilder("<!DOCTYPE HTML>" + Environment.NewLine);
        HtmlTextWriter textWriter = new HtmlTextWriter(new StringWriter(sb));
        base.Render(textWriter);
        writer.Write(sb.ToString());
    }




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签