模态窗口

 <input type="button" ID="Button1" Text="..." OnClick="javascript:var sRe=window.showModalDailog('a.aspx?id= <%# Eval("Index") %>','','')"
asp.net单击gridview或button弹出新窗口实现方法
2007-09-05 12:02 P.M.
先是父页面  
<form id="form1" runat="server"> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;  
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="CityID" DataSourceID="AccessDataSource1" OnRowDataBound="GridView1_RowDataBound">  
      <Columns>  
       <asp:BoundField DataField="CityID" HeaderText="CityID" InsertVisible="False" ReadOnly="True" SortExpression="CityID" />  
                                 <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />  
                                 <asp:BoundField DataField="provinceID" HeaderText="provinceID" SortExpression="provinceID" />  
           </Columns>  
</asp:GridView>  
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/test.mdb" SelectCommand="SELECT * FROM [CityTable]"></asp:AccessDataSource>  
</form>  
   
===================================  
public partial class CSDN_webform1 :      System.Web.UI.Page  
{  
protected void Page_Load(object sender, EventArgs e)  
{}  
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)  
{  
      if (e.Row.RowIndex > -1)  
      {  
       e.Row.Attributes.Add("onclick", "window.showModalDialog('webform3.aspx?index="+(e.Row.RowIndex+1).ToString()+"&gridid="+this.GridView1.ClientID+"');");  
      }  
}
}

子页面:  
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="webform3.aspx.cs" Inherits="CSDN_webform3" %>  
<!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>无标题页</title>  
<base target="_self" />  
</head>  
<body>  
<form id="form1" runat="server">  
      <div>  
       <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>  
</form>  
</body>  
</html>  
============================================  
public partial class CSDN_webform3 : System.Web.UI.Page  
{  
protected void Page_Load(object sender, EventArgs e)  
{  
      Response.Write(Request.QueryString["index"]);  
}  
protected void Button1_Click(object sender, EventArgs e)  
{  
      ClientScript.RegisterStartupScript(typeof(string), "","<script>parent.document.forms[0].submit();window.close();</script>");  
}  
}

 
上面是在网上找的方法,试过了,好用的,这种方法关闭子窗口时会刷新父页面,如果不想刷新父页面,可以把子页面放框架页里,步骤是新建一个页面,把<body>部分去掉,添入html代码如下:

<head runat="server">
           <title>无标题页</title>
</head>
<frameset rows="0,*">
         <frame src="about:blank">
         <frame src="*.aspx"><!--*为子页名-->
</frameset>
</html>
调用时把父页面的蓝色字部分换成框架页名就行了,而且这种方法也支持在子页面响应服务器事件,如button等.就是传值比较麻烦,我曾用的方法是如下
在父页面的加载事件中写:
ClientScriptManager csm = Page.ClientScript;
                   if (!csm.IsClientScriptBlockRegistered("clientScript"))
                   {
                       String strScript = "<script>/r/n";
                       strScript += "function OpenWin(){/r/n";
                       strScript += "var str=window.showModalDialog('frm_frame.aspx',document.Form1.Hidden1.value)/r/n";
                       //strScript += "if(str!=null)         document.Form1.Hidden1.value=str/r/n";
                       strScript += "}/r/n";
                       strScript += "</script>";
                       csm.RegisterClientScriptBlock(this.GetType(), "clientScript", strScript);
                   }
                   btnEdit.Attributes.Add("onclick", "OpenWin()");
            //电击btnEdit,弹出子窗体
子页面:
MyBody.Attributes.Add("onload", "document.form1.TextBox1.value=window.parent.dialogArguments");
这样子页面TextBox1就可以显示父页面Hidden1的值了.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值