January 17, 2009

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



Giving me +1 tells me you liked this article! Thanks in advance




About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

8 Responses to "Open a PopUp Window on the ASP.NET Button Click event and pass Parameters"
  1. Anonymous said...
    August 4, 2009 at 6:46 AM

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

  2. boydd_uk said...
    October 30, 2009 at 5:35 AM

    Problem is this is blocked by a pop up blocker

  3. sathiya said...
    February 11, 2010 at 2:15 AM

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

  4. GAUTAM said...
    March 17, 2010 at 9:30 AM

    thanks , i was looking for the solution

    thanks

  5. Thiru said...
    April 23, 2010 at 5:02 AM

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

  6. dhara said...
    May 18, 2011 at 12:57 AM

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

  7. Anonymous said...
    April 23, 2012 at 10:18 AM

    Nice! Saved lot of time

  8. Anonymous said...
    April 10, 2013 at 10:54 PM

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

 

Copyright © 2009-2013 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions