我正在asp.net(vb)中编写一个应用程序,我有一个问题是在用户关闭窗口打开之前是否设置了textboxvalue有没有办法阻止这个?
Sub btnSelectDate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSelectDate.Click
Dim Window As String
Window = " window.open('About.aspx', 'MsgWindow', 'width=500, height=500'); "
ClientScript.RegisterClientScriptBlock(Me.GetType, "date", Window, True)
textboxvalue.Text = "hello"
Page_Load()
End Sub
答案 0 :(得分:0)
如果要在弹出窗口关闭后设置textboxvalue的文本,可以在客户端代码中执行此操作(请参阅Capture the close event of popup window in JavaScript):
Dim jsCode As String
jsCode = "var wnd = window.open('About.aspx', 'MsgWindow', 'width=500, height=500'); wnd.onbeforeunload = function() { document.getElementById('textboxvalue').value = 'Hello'; };"
ClientScript.RegisterClientScriptBlock(Me.GetType, "date", jsCode, True)
这里我假设 textboxvalue 是呈现的HTML中TextBox的实际ID。
更新 - 要处理按钮,请单击客户端代码:
<asp:Button ID="btnSelectDate" runat="server" OnClientClick="ProcessSelectDate(); return false;" />
<script>
function ProcessSelectDate()
{
var wnd = window.open('About.aspx', 'MsgWindow', 'width=500, height=500');
wnd.onbeforeunload = function () { document.getElementById('textboxvalue').value = 'Hello'; var form = document.forms['form1']; form.submit(); };
}
</script>
其中form1是表单的ID。
答案 1 :(得分:0)
试试这个:
1-在关闭窗口的脚本文件中添加以下代码
window.opener.location.href = "YouPage?FromPopup=1"
2-
Request.QueryString["FromPopup"]
您可以在其中添加代码