Dynamically change the document type of an aspx page

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

On one of the pages I need to change the doctype, otherwise the third-party control will not display correctly.

How can I change the doctype of this particular page only without affecting the rest of the pages?

+3
source share
4 answers

The easiest way is to create another copy of your main page, change the doctype type in it, and use the page with a new wizard.

+5
source

I don't know if this will 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>);

- .., , , , Chris Lively...

+1

Have you used the 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 Page_Load you can:

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

This also works.

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());
    }
+1
source

Source: https://habr.com/ru/post/1724386/


All Articles