0

I am writing an application in asp.net (vb), I am having a problem wher textboxvalue is being set before the window open has been closed by the user is there a way of preventing this?

 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
OneFineDay
  • 9,004
  • 3
  • 26
  • 37
ManWithNoName
  • 67
  • 2
  • 13

2 Answers2

0

If you want to set the text of textboxvalue after the popup window has closed, you can do it in the client code (see 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)

Here I assume that textboxvalue is the actual ID of the TextBox in the rendered HTML.

UPDATE - To process the button click in client code:

<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>

Where form1 is the ID of the form.

Community
  • 1
  • 1
ConnorsFan
  • 70,558
  • 13
  • 122
  • 146
  • Could i call the page_load in the javascript too? – ManWithNoName Mar 15 '15 at 17:33
  • In order to call server-side code, you would have to submit the form or run some AJAX command (I am not very familiar with AJAX). – ConnorsFan Mar 15 '15 at 17:40
  • By the way, if everything is done in client code, you could eliminate the btnSelectDate_Click server-side procedure completely, and use the OnClientClick attribute of btnSelectDate instead. – ConnorsFan Mar 15 '15 at 18:04
0

Try this :

1- In the script file that closes the window add the following code

window.opener.location.href = "YouPage?FromPopup=1"

2- from Parent window check

Request.QueryString["FromPopup"]

where you can add code

Hany Hassan
  • 320
  • 2
  • 10