zoukankan      html  css  js  c++  java
  • Asp.Net父子页访问

    效果:比如一个设备管理系统的某处要填入设备编号,但设备编号通常比较难记,而可能记住的只是哪个部门哪个位置的设备。因此,我们想在文本框旁边加一个按 钮,点击之后弹出一个子页面,这里有设备编号、设备的各项详情对照的一个表格,我只要根据位置找到该设备,双击此记录,设备编号便填上去了。

    实现过程:
    父页面

    打开新窗口的javascript函数为:

          <script type="text/javascript" language="javascript">           
               
    function openpage(htmlurl) 
            {
            
    var newwin=window.open(htmlurl,"newWin","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes,top=100,left=200,width=650,height=300");
            newwin.focus();
            
    return false;
            }

            
    </script>

     在按钮中调用:

    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return openpage('child.aspx');"/>

     子页面绑定gridview的数据源,并在它的RowDataBound事件里写代码如下:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            
    string s = "window.opener.document.getElementById('txbRoleName').value='" + e.Row.Cells[1].Text + "'; "+
                
    "window.opener.document.getElementById('txbRoleID').value='" + e.Row.Cells[0].Text + "'; " 
                
    +"window.close();";
            
    if (e.Row.RowType != DataControlRowType.Header)
            {
                e.Row.Attributes.Add(
    "ondblclick", s);//双击选择
                
    //当鼠标移到的时候设置该行颜色为"", 并保存原来的背景颜色
                e.Row.Attributes.Add("onmouseover""currentcolor=this.style.backgroundColor;this.style.backgroundColor='#C0C0FF';this.style.cursor='hand';");
                
    //当鼠标移走时还原该行的背景色
                e.Row.Attributes.Add("onmouseout""this.style.backgroundColor=currentcolor");
            }
        }
    说明:通过window.open打开新页面,两个页面之前便有了一种父子关系。子页通过opener可以访问父页(控件及写在父页的js函数),父页同 样通过sub可以访问子页。如在父页有个js函数sayhello(),在子页中只需要opener.sayhello()便可以调用了。

    只使用很少的Javascript代码与asp.net结合,便完成了一种很好用的效果。

     转自:http://www.cnblogs.com/jeffamy/archive/2006/05/11/396880.html

  • 相关阅读:
    数据结构和算法(Golang实现)(14)常见数据结构-栈和队列
    数据结构和算法(Golang实现)(20)排序算法-选择排序
    数据结构和算法(Golang实现)(18)排序算法-前言
    数据结构和算法(Golang实现)(22)排序算法-希尔排序
    数据结构和算法(Golang实现)(21)排序算法-插入排序
    数据结构和算法(Golang实现)(27)查找算法-二叉查找树
    关于SpringMVC映射模型视图的几点小事
    关于spring中事务管理的几件小事
    关于spring中AOP的几件小事
    关于spring中bean配置的几件小事
  • 原文地址:https://www.cnblogs.com/scottckt/p/1320828.html
Copyright © 2011-2022 走看看