我正在使用JavaScript将一个值从对话框传递到asp父页面的简单示例/快速修复 - 如果java脚本是最好的选项!
我已经多次尝试这样做,但到目前为止每次努力都失败了。
lblVarSelectedDate.Text是我想回发到父页面的值,显示为lblVarChildSelectedDate值。
以下是Register.aspx页面(PARENT)的一部分
<table>
<tr>
<td colspan="5" align="center"><asp:Label ID="lblDate" runat="server" Text="Selected Date: "></asp:Label><asp:Label ID="lblVarChildSelectedDate" runat="server" ></asp:Label></td>
<td colspan="1" align="center"><asp:Button ID="btnSelectDate" runat="server" Text="Date" /> </td>
</tr
<tr>
<td><asp:Button ID="btOK" runat="server" Text="Ok" /> </td>
</tr>
</table>
这是寄存器后面的VB.aspx ...
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Sub btnSelectDate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSelectDate.Click
Dim Window As String
Window = " window.open('selectdate.aspx', 'MsgWindow', 'width=500, height=500');"
ClientScript.RegisterClientScriptBlock(Me.GetType, "date", Window, true)
End Sub
Sub btnOk_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btOK.Click
End Sub
现在她是我的子页面selectdate.aspx ..
<table>
<tr>
<td colspan="6"><asp:Calendar ID="calSelecter" runat="server" OnSelectionChanged="SelectionChange"></asp:Calendar></td>
</tr>
<tr>
<td colspan="6" align="center"><asp:Label ID="lblConsSelectedDate" runat="server" Text="Selected Date: "></asp:Label><asp:Label ID="lblVarSelectedDate" runat="server" ></asp:Label></td>
</tr
<tr>
<td><asp:Button ID="btOK" runat="server" Text="Ok" /> </td>
</tr>
</table>
她是儿童页面背后的vb。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
calSelecter.SelectedDate = Date.Today
lblVarSelectedDate.Text = Date.Today
End Sub
Sub btnOk_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btOK.Click
' .... on click post back to parent page lblVarSelectedDate.Text
End Sub
Sub SelectionChange(ByVal sender As Object, ByVal e As EventArgs)
lblVarSelectedDate.Text = calSelecter.SelectedDate
End Sub
非常感谢
答案 0 :(得分:0)
如果您的应用程序设计允许它,并且您想要尝试它,我将为您的子窗口使用jQuery对话框而不是单独的浏览器窗口。然后,您可以使用jQuery从对话框上的选定日期填充“父”页面上的字段,而无需回发。
事实上,根据您最终要做的事情,您甚至可能会发现jQuery UI Datepicker小部件满足您的需求,并且您不需要任何自定义编程:
http://jqueryui.com/datepicker/
如果它不符合您的需求,请在评论中告诉我,我将使用jQuery对话框解决方案的特定代码填写此答案。