导航

IFrame+Js+Div+Css 无刷新修改

Posted on 2011-02-17 16:50  夹心刺猬  阅读(514)  评论(0)    收藏  举报

  

<!--列表页-->

 <script type="text/javascript">

   <!--显示操作页面-->
        function DetailShow(linkUrl) {
            var iframeDetails = document.getElementById("iframeDetails");
            iframeDetails.src = linkUrl;
            var divIframeControl = document.getElementById("divIframeControl");
            divIframeControl.style.display = "block";
        }

      <!--隐藏操作页面 返回值 来选择 是否 提交页面绑定数据-->
        function DetailHidden(sign) {
            var divIframeControl = document.getElementById("divIframeControl");
            divIframeControl.style.display = "none";
            var iframeDetails = document.getElementById("iframeDetails");
            iframeDetails.src = "";
            if (sign > 0) {
                document.getElementById("hdToBind").value=sign;
                document.getElementsByTagName("form")[0].submit();
            }
        }
</script>

<!--用Css来保证 Div与IFrame 在列表页面之上-->
<div style=" position:relative; width:100%; padding-left:3px; padding-top:0px; margin-top:0px;">
<div style=" position:absolute; width:100%; z-index:2; height:auto;display:none;" id="divIframeControl"><iframe src="" id="iframeDetails" scrolling="no" frameborder="0"  style=" height:600px; padding-top:0px; margin-top:0px; border-width:0px;" width="100%"></iframe></div>
</div>

<!--来保存 并提交服务器 判断是否绑定数据-->

<input type="hidden"  id="hdToBind" value="" />

<!--每次还原 hdToBind 是不需要更新状态 避免重复更新-->

<script type="text/javascript">document.getElementById("hdToBind").value="0";</script>

 List.cs 文件


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

    //第一次直接绑定数据
            BindData();
        }
        else
        {

    //如果数据更改就绑定数据 主要是考虑 到服务器事件

            if (Request.Form["hdToBind"].Equals("1"))
            {
                BindData();
            }
        }
    }

<!--操作页-->

<!--调用父页面(列表页)方法 告之 没有进行操作 不用进行重新绑定-->

<input type="button" style=" margin-left:20px;"  onclick="window.parent.DetailHidden(0);" value="返  回" />

.cs 文件

//注册脚本 同样 调用父页面(列表页)方法 告之 数据已经改变 需要重新绑定

ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "window.parent.DetailHidden(1);", true);