[总结]关于模态窗口(showModalDialog)的专题讨论!

博客主要介绍了模态窗口的操作,包括打开、关闭及传递参数的方法。给出了相关代码示例,如使用window.showModalDialog打开窗口、window.close关闭窗口等。还解决了aspx页面在showmodeldialog下提交重新打开页面的问题,以及在数据绑定模式窗体中传递选中行相关值的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.模态窗口的打开
2.模态窗口的关闭
3.模态窗口的传递参数。
4.其他。。。。


1.window.showModalDialog("DialogPage.aspx","newwin","dialogHeight: 200px; dialogWidth: 150px; dialogTop: 458px; dialogLeft: 166px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;");

2.window.close();

3.传值
ParentPage.aspx:
window.showModalDialog("DialogPage.aspx?para1=aaa&para2=bbb");

DialogPage.aspx:
string str1=Request.QueryString["para1"].toString();
string str2=Request.QueryString["para2"].toString();

返回值
DialogPage.aspx:
window.returnValue="aaa";

ParentPage.aspx:
var str=window.showModalDialog("DialogPage.aspx");

4.
aspx页面在showmodeldialog情况下为什么一提交就重新打开一个页面?
showmodaldialog打开的页面中在<head></head>之间加入一行:<base target="_self">

 

 

5.如果是在数据绑定的模式窗体中,还可以在DataGrid中创建一个模板列,再加入Html的按钮,在按钮中加入:
OnClick="returnValue='<%#DataBind.Eval(Container.DataItem,"Name")%>';window.close()"
就可以实现在模式对话框中传递DataGrid的具体选中的行的相关值。


6.例子
WebForm2.aspx.vb
    Inherits System.Web.UI.Page
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Button2 As System.Web.UI.WebControls.Button
    Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button1.Attributes.Add("onclick", "var st=window.showModalDialog('user.aspx?val='+document.all('TextBox1').value);document.all('TextBox1').value=st;return st;")
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        RegisterStartupScript("key", "<script>window.opener=null;window.close(this);</script>")
    End Sub
user.aspx.vb
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents cancel As System.Web.UI.WebControls.Button
    Protected WithEvents ok As System.Web.UI.WebControls.Button
    Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox   
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim str As String
        If Not IsPostBack Then
            str = Request.QueryString("val")
            TextBox1.Text = str
        End If
    End Sub
    Private Sub cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancel.Click
        RegisterStartupScript("key", "<script>window.returnValue='null';window.opener=null;window.close(this);</script>")
    End Sub
    Private Sub ok_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ok.Click
        RegisterStartupScript("key", "<script>window.returnValue=document.all('TextBox2').value;window.opener=null;window.close(this);</script>")
    End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值