Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com

Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com

I have a single page(created before Master pages were available) that loaded dynamically one or another user control.Some child controls have css for quirk mode, but for new controls I want to use latest DocType
<!DOCTYPE html>
The solution is to set it dynamically in code-behind depending on current control to load(the code is copied from http://stackoverflow.com/questions/174916/how-do-you-specify-your-content-type-in-asp-net/6932768#6932768)


=========aspx===============
<%@ 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">
==============code behind=========
protected void Page_Load(object sender, EventArgs e)
{
string docType;
if(PageId==”OLD”)
docType= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
else
docType= "<!DOCTYPE html>”

this.DocType.Text= docType;

}

Posted on Friday, September 23, 2011 9:38 PM ASP.NET , CSS/DHTML/JavaScript | Back to top


Comments on this post: Change DocType dynamically

# re: Change DocType dynamically
Requesting Gravatar...
My "master" page knows which control has been loaded(stored in PageID parameter), and I can hardcode the controls that required old docType
Left by Michael Freidgeim on Nov 26, 2011 8:52 AM

# re: Change DocType dynamically
Requesting Gravatar...
Thanks!
Left by nah on Nov 26, 2013 1:36 PM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net