iFrame页面数据的绑定与读取
2009-03-11 10:20
225 查看
iframeStudy.aspx.cs
/***********iFrame页面数据的绑定与读取********************** * 为iFrame加上runat=server的作法,没有尝试, * 需要考虑window.onload与Page_Load的执行次序吧 * * 用HiddenField做中介的方法,容易出错的地方: * 1.window.onload事件执行的时候iframe一般没有加载完成,要判断 * 2.表单提交的时候,用js为HiddenField赋值onsubmit=bSubmit(); ***********************************************************/ 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; public partial class iframeStudy : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) Bind(); } private void Bind() { this.hfEdit.Value = "绑定数据"; } protected void btnSubmit_Click(object sender, EventArgs e) { Response.Write("<mce:script type="text/javascript"><!-- alert('" + this.hfEdit.Value + "'); // --></mce:script>"); } }iframeStudy.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="iframeStudy.aspx.cs" Inherits="iframeStudy" %> <!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>iFrame页面数据的绑定与读取</title> <mce:script type="text/javascript"><!-- //为iFrame绑定数据 function bindIframe() { //判断iframe页面是否加载完成 if(window.frames[0].document.readyState=="complete") { window.childFrame.document.getElementById("txtEdit").value=document.getElementById("hfEdit").value; } else//如果没有加载完成,过一秒钟再执行 setTimeout("bindIframe()",1000); } //表单提交的时候,改变HiddenField的值,HiddenField相当于一个中介吧. function bSubmit(){ document.getElementById("hfEdit").value=window.childFrame.document.getElementById("txtEdit").value; } window.onload=function(){ bindIframe(); } function fShow(){ alert(document.getElementById("hfEdit").value); } // --></mce:script> </head> <body> <form id="form1" runat="server" onsubmit="bSubmit();"> <div> <asp:HiddenField ID="hfEdit" runat="server" /> </div> <div> <iframe runat="server" id="childFrame" width="100%" height="100%" src="childFrame.htm" mce_src="childFrame.htm" frameborder="0"> </iframe> </div> <input id="btnOk" type="button" value="Ok" onclick="fShow();" /> <asp:Button ID="btnSubmit" runat="server" Text="提交" OnClick="btnSubmit_Click" /> </form> </body> </html>childFrame.htm
<!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> <title>iFrame内的页面</title> </head> <body> <textarea id="txtEdit" cols="20" rows="2">
相关文章推荐
- EasyUI中iframe嵌入页面,包含datagrid数据动态绑定,页面内容的高度自适应问题
- flex :读取access数据库数据 转化为xml 然后在flex页面显示绑定图片
- 页面读取EXCEL表并将数据导入到Oracle(DWR异步机制,iframe页面嵌套)
- 从XML文件中读取数据绑定到DropDownList-.Net编程教程
- 将图片保存到ORACEL数据库和读取数据显示到页面
- SharePoint2010沙盒解决方案基础开发——开发webpart读取绑定列表数据,并以一定的格式显示(加css样式)
- WebForm页面数据绑定总结
- 使用EJS(模板引擎)动态绑定页面中的数据
- js iframe子父页面读取方式
- XML文件读取数据绑定到DropDownList
- iframe 大数据量传参 本地能调用远程页面 不存在跨域问题 js组件调用原理
- C# winform读取页面相关数据的方法
- ASP.NET Web API实践系列07,获取数据, 使用Ninject实现依赖倒置,使用Knockout实现页面元素和视图模型的双向绑定
- 在前台ASPX页面中直接判断绑定的数据是否为空!
- Web页面报错: Eval()、XPath() 和 Bind() 这类数据绑定方法只能在上下文中使用
- 从XML文件读取数据绑定到列表控件
- 从父页面读取和操作iframe中内容方法
- tab切换页面+cookie跳过登录页面+json解析+tree Weight绑定json数据
- Ajax的一个简单例子--从一个文件文件中读取数据显示到页面中
- 从数据库读取数据绑定到TreeView(内含设置样式,图片)