Asp.net 实现弹窗打开子窗口并通过Session传值

弹窗打开新窗口。
母窗口放置【弹窗】按钮,点击【弹窗】按钮,向Session中储存值,并打开子窗口。
子窗口中通过标签显示Session中的值。另外在子窗口中放置【选择】按钮,点击【选择】按钮,向Session中储存值,并向母窗口Submit。
母窗口PostBack,页面装载时,取得Session中的值,显示在TextBox中。

●母窗口aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> 

<!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> 
</head> 
<body> 
    <form id="form1" runat="server"> 
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
        <asp:Button ID="Button1" runat="server" Text="弹窗" /> 
    </form> 
</body> 
</html> 

●母窗口aspx.vb

Partial Class _Default 
    Inherits System.Web.UI.Page 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
        If IsPostBack Then 
            Me.TextBox1.Text = CStr(Session("ITEM")) 
        End If 
    End Sub 

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 
        Session("KEY") = "AAA" 

        Dim scriptStr As String 
        scriptStr = "<script type='text/javascript'>" 
        scriptStr += "window.open('Default2.aspx','_blank','width=300,height=300');"
        scriptStr += "</script>" 

        ClientScript.RegisterStartupScript(Me.GetType(), "Default2画面", scriptStr) 
    End Sub 
End Class 

●子窗口aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %> 

<!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> 
</head> 
<body> 
    <form id="form1" runat="server"> 
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label> 
        <asp:Button ID="Button1" runat="server" Text="选择" /> 
    </form> 
</body> 
</html> 

●子窗口aspx.vb

Partial Class Default2 
    Inherits System.Web.UI.Page 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
        Me.Label1.Text = CStr(Session("KEY")) 
End Sub 

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 
        Session("ITEM") = "BBB" 

        Dim scriptStr As String 
        scriptStr = "<script type='text/javascript'>" 
        scriptStr += "window.opener.form1.submit();" 
        scriptStr += "window.close();" 
        scriptStr += "</script>" 

        ClientScript.RegisterStartupScript(Me.GetType(), "Default2画面", scriptStr) 

    End Sub 
End Class 

原文链接:http://www.cocoaliz.com/asp.net/index.php/68/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。