Open a PopUp Window on the ASP.NET Button Click event and pass Parameters

A User asked me how to Open a PopUp window when the user clicks on an ASP.NET Button Server Control. He also wanted to pass parameters to the url. Here's how it is done:

C#


protected void Button1_Click(object sender, EventArgs e)

{

    string queryString = 

        "http://localhost:39208/TreeView.aspx?param1=" 

        + TextBox1.Text.Trim();   

    string newWin = 

        "window.open('" + queryString + "');";

    ClientScript.RegisterStartupScript

        (this.GetType(), "pop", newWin, true);

}



VB.NET


    Protected Sub Button1_Click(ByVal sender As Object, _

                                ByVal e As EventArgs)

        Dim queryString As String = _

           "http://localhost:39208/TreeView.aspx?param1=" & _

            TextBox1.Text.Trim()

        Dim newWin As String = _

           "window.open('" & queryString & "');"

        ClientScript.RegisterStartupScript(Me.GetType(), _

                                       "pop", newWin, True)

    End Sub

11 comments:

  1. Simple, yet saved me a lot of time. Thank you very much!

    ReplyDelete
  2. Problem is this is blocked by a pop up blocker

    ReplyDelete
  3. its work fine but problem is that click on button page is refreshed.

    ReplyDelete
  4. thanks , i was looking for the solution

    thanks

    ReplyDelete
  5. ya..i got it. thanks for ur solution.

    ReplyDelete
  6. thank you for the code, saved alot of time.. :)

    ReplyDelete
  7. Nice! Saved lot of time

    ReplyDelete
  8. thank you for the idea!! like it and solved my problem :)

    ReplyDelete
  9. when click a button two windows will be open

    ReplyDelete
  10. what is that textbox1 means in the code

    ReplyDelete