C#.net 在页面加载时可不可以给客户端<html>中加入数据??
C#.net 在页面加载时可不可以给客户端 <html> 中加入数据??如:
<html xmlns:v= "urn:schemas-microsoft-com:vml ">
------解决方案--------------------this.h1.Attributes.Add( "xmlns: ", "urn:schemas-microsoft-com:vml ");
<html xmlns= "http://www.w3.org/1999/xhtml " id= "h1 " runat= "server " >
------解决方案--------------------用Render,我以前用过。
------解决方案-----------------------Default5.aspx---
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "Default5.aspx.cs " Inherits= "Default5 " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html>
<head runat= "server ">
<title> Untitled Page </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
</div>
</form>
</body>
</html>
---Default5.aspx.cs---
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text.RegularExpressions;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void Render(HtmlTextWriter writer)
{
TextWriter tempWriter = new StringWriter();
base.Render(new HtmlTextWriter(tempWriter));
writer.Write(Regex.Replace(tempWriter.ToString(), " <html> ", " <html xmlns:v=\ "urn:schemas-microsoft-com:vml\ "> "));
}
}
这样可以的,我试了,要注意你的ASPX文件中必须有一个 <html>