I'm trying to open a new browser window, allow the user to select a date, pass the date back to a textbox on the parent window, and close the child. Everything seems to work fine except the textbox does not get filled with the date. What am I missing? Is there a better way that this method? Examples are always welcome.
ParentWindow.aspx:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ParentWindow.aspx.vb" Inherits="PopUpCalendar.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content=" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:button id="btnPopUp" style="Z-INDEX: 101; LEFT: 182px; POSITION: absolute; TOP: 138px" runat="server" Text="Button"></asp:button>
<asp:TextBox id="txtDate" style="Z-INDEX: 102; LEFT: 300px; POSITION: absolute; TOP: 140px" runat="server" Width="189px" Height="30px"></asp:TextBox></form>
</body>
</HTML>
ParentWindow.aspx.vb:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents txtDate As System.Web.UI.WebControls.TextBox
Protected WithEvents btnPopUp As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnPopUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPopUp.Click
Dim strFeatures As String
Dim strScript As String
Dim strURL As String = "ChildWindow.aspx"
strFeatures = "'height=320;width=320;'"
strScript = "<script language=javascript>"
strScript &= "window.open('" & strURL & "',''," & strFeatures & ""
strScript &= "</script>"
Response.Write(strScript)
End Sub
End Class
ChildWindow.aspx:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ChildWindow.aspx.vb" Inherits="PopUpCalendar.ChildWindow"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>ChildWindow</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content=" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Calendar id="Calendar1" style="Z-INDEX: 101; LEFT: 131px; POSITION: absolute; TOP: 96px" runat="server"></asp:Calendar></form>
</body>
</HTML>
ChildWindow.aspx.vb:
Public Class ChildWindow
Inherits System.Web.UI.Page
Protected WithEvents Calendar1 As System.Web.UI.WebControls.Calendar
#Region " Web Form Designer Generated Code "
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
Dim strScript As String
Dim strDate As String = Calendar1.SelectedDate
strScript = "<script language=javascript>"
strScript &= "window.opener.form1.txtDate.text ='"
strScript &= strDate & "';"
strScript &= "window.close();"
strScript &= "</script>"
Response.Write(strScript)
End Sub
End Class
ParentWindow.aspx:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ParentWindow.aspx.vb" Inherits="PopUpCalendar.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content=" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:button id="btnPopUp" style="Z-INDEX: 101; LEFT: 182px; POSITION: absolute; TOP: 138px" runat="server" Text="Button"></asp:button>
<asp:TextBox id="txtDate" style="Z-INDEX: 102; LEFT: 300px; POSITION: absolute; TOP: 140px" runat="server" Width="189px" Height="30px"></asp:TextBox></form>
</body>
</HTML>
ParentWindow.aspx.vb:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents txtDate As System.Web.UI.WebControls.TextBox
Protected WithEvents btnPopUp As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnPopUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPopUp.Click
Dim strFeatures As String
Dim strScript As String
Dim strURL As String = "ChildWindow.aspx"
strFeatures = "'height=320;width=320;'"
strScript = "<script language=javascript>"
strScript &= "window.open('" & strURL & "',''," & strFeatures & ""
strScript &= "</script>"
Response.Write(strScript)
End Sub
End Class
ChildWindow.aspx:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ChildWindow.aspx.vb" Inherits="PopUpCalendar.ChildWindow"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>ChildWindow</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content=" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Calendar id="Calendar1" style="Z-INDEX: 101; LEFT: 131px; POSITION: absolute; TOP: 96px" runat="server"></asp:Calendar></form>
</body>
</HTML>
ChildWindow.aspx.vb:
Public Class ChildWindow
Inherits System.Web.UI.Page
Protected WithEvents Calendar1 As System.Web.UI.WebControls.Calendar
#Region " Web Form Designer Generated Code "
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
Dim strScript As String
Dim strDate As String = Calendar1.SelectedDate
strScript = "<script language=javascript>"
strScript &= "window.opener.form1.txtDate.text ='"
strScript &= strDate & "';"
strScript &= "window.close();"
strScript &= "</script>"
Response.Write(strScript)
End Sub
End Class