asp.net中Post表单保存页面状态并输出源码的实现方法
更新时间:2012年08月27日 22:32:52 作者:
先执行脚本,复制源码到隐藏域里,再输出源码,注意代码红色设置
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)
您可能感兴趣的文章:
相关文章
ASP.NET MVC:Filter和Action的执行介绍
ASP.NET MVC之Filter和Action的执行介绍,需要的朋友可以参考2012-11-11
关于HttpHandler与HttpModule的理解和应用方法
本篇文章小编将为大家介绍,关于HttpHandler与HttpModule的理解和应用方法,有需要的朋友可以参考一下2013-04-04
asp.net 文件上传与刷新与asp.net页面与iframe之间的数据传输
众所周知微软所提供的updatepanel不能支持文件上传的异步刷新,但是往往当你在项目中的其他页面实现了异步刷新之后,客户就会问你为什么有文件上传的页面就不能实现异步刷新呢?这时我们可能说一堆理由,但是最后大部分还是会妥协于客户。2009-12-12
ASP.Net使用System.Security.Principal模拟用户
这篇文章介绍了ASP.Net使用System.Security.Principal模拟用户的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2022-05-05


最新评论