就象这个下面代码 DataSet ds = getDate(); HtmlGenericControl UL = new HtmlGenericControl(); UL = createmenu(ds, null, UL); string s = UL.InnerHtml; //在这里的时候说:无法获取 的内部内容,因为该内容不是文本。 我想得到是服务器输出html流。
你要去看aspx是怎么解析成html的。比如说:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 这个声明:在aspx页面中你去遍历Page.Controls 你就可以发现他只不过是aspx页面声明System.Web.UI.LiteralControl的ClientID == "ctl00"(如果页面只有这一句话时)控件,他的Text就是上面那一句话。 对于form你也可以在遍历中获取。 但是他们的ClientID是不同的
你新建一个aspx页面不写任何东西 在Page_Load中遍历controls foreach (Control c in this.Controls) { if (c.ClientID == "form1") { string text = (c as System.Web.UI.HtmlControls.HtmlForm).InnerHtml; //(c as System.Web.UI.HtmlControls.HtmlForm).InnerHtml="test";你也可以赋值。 Response.Write(text); Response.End(); } }
DataSet ds = getDate();
HtmlGenericControl UL = new HtmlGenericControl();
UL = createmenu(ds, null, UL); string s = UL.InnerHtml; //在这里的时候说:无法获取 的内部内容,因为该内容不是文本。 我想得到是服务器输出html流。
这个声明:在aspx页面中你去遍历Page.Controls
你就可以发现他只不过是aspx页面声明System.Web.UI.LiteralControl的ClientID == "ctl00"(如果页面只有这一句话时)控件,他的Text就是上面那一句话。
对于form你也可以在遍历中获取。 但是他们的ClientID是不同的
在Page_Load中遍历controls foreach (Control c in this.Controls)
{
if (c.ClientID == "form1")
{
string text = (c as System.Web.UI.HtmlControls.HtmlForm).InnerHtml;
//(c as System.Web.UI.HtmlControls.HtmlForm).InnerHtml="test";你也可以赋值。
Response.Write(text);
Response.End();
}
}
服务器控件的机制 跟HTML的 不是一个概念