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



'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


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

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

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

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

    Problem is this is blocked by a pop up blocker

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

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

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

    thanks , i was looking for the solution

    thanks

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

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

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

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

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

    Nice! Saved lot of time

 

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