asp.net中Post表单保存页面状态并输出源码的实现方法
程序员文章站
2024-03-06 21:38:32
html页面 复制代码 代码如下: <%@ page language="c#" autoeventwireup="true" codefile="default.a...
html页面
<%@ page language="c#" autoeventwireup="true" codefile="default.aspx.cs" inherits="_default"
validaterequest="false" %>
<%@ register src="usercontrol/ucone.ascx" tagname="ucone" tagprefix="uc1" %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>页面提交后提取html源码(保持状态)</title>
<script type="text/javascript">
function getallcode_ie() {
document.getelementbyid("hid_html").value=document.documentelement.outerhtml;
}
function getallcode_firefox(){
return document.body.innerhtml.tostring();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:ucone id="ucone1" runat="server" />
</div>
</form>
</body>
</html>
用户控件
<%@ control language="c#" autoeventwireup="true" codefile="ucone.ascx.cs" inherits="usercontrol_ucone" %>
<asp:textbox id="txtname" runat="server"></asp:textbox>
<asp:button id="btnadd" runat="server" text="add" />
<input type="hidden" id="hid_html" name="hid_html" />
<div id="div_inner_input" runat="server">
</div>
用户控件后台:
public partial class usercontrol_ucone : system.web.ui.usercontrol
{
protected void page_load(object sender, eventargs e)
{
this.btnadd.attributes.add("onclick", "return getallcode_ie();");
}
protected override void oninit(eventargs e)
{
base.oninit(e);
this.btnadd.click += new eventhandler(btnadd_click);
}
void btnadd_click(object sender, eventargs e)
{
this.div_inner_input.innertext = request.form["hid_html"].tostring();
}
}
作者: ruanyiniu(ryan)
复制代码 代码如下:
<%@ page language="c#" autoeventwireup="true" codefile="default.aspx.cs" inherits="_default"
validaterequest="false" %>
<%@ register src="usercontrol/ucone.ascx" tagname="ucone" tagprefix="uc1" %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>页面提交后提取html源码(保持状态)</title>
<script type="text/javascript">
function getallcode_ie() {
document.getelementbyid("hid_html").value=document.documentelement.outerhtml;
}
function getallcode_firefox(){
return document.body.innerhtml.tostring();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:ucone id="ucone1" runat="server" />
</div>
</form>
</body>
</html>
用户控件
复制代码 代码如下:
<%@ control language="c#" autoeventwireup="true" codefile="ucone.ascx.cs" inherits="usercontrol_ucone" %>
<asp:textbox id="txtname" runat="server"></asp:textbox>
<asp:button id="btnadd" runat="server" text="add" />
<input type="hidden" id="hid_html" name="hid_html" />
<div id="div_inner_input" runat="server">
</div>
用户控件后台:
复制代码 代码如下:
public partial class usercontrol_ucone : system.web.ui.usercontrol
{
protected void page_load(object sender, eventargs e)
{
this.btnadd.attributes.add("onclick", "return getallcode_ie();");
}
protected override void oninit(eventargs e)
{
base.oninit(e);
this.btnadd.click += new eventhandler(btnadd_click);
}
void btnadd_click(object sender, eventargs e)
{
this.div_inner_input.innertext = request.form["hid_html"].tostring();
}
}
作者: ruanyiniu(ryan)