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:


protected void Button1_Click(object sender, EventArgs e)


    string queryString = 


        + TextBox1.Text.Trim();   

    string newWin = 

        "'" + queryString + "');";


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



    Protected Sub Button1_Click(ByVal sender As Object, _

                                ByVal e As EventArgs)

        Dim queryString As String = _

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


        Dim newWin As String = _

           "'" & queryString & "');"

        ClientScript.RegisterStartupScript(Me.GetType(), _

                                       "pop", newWin, True)

    End Sub

About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.


Anonymous said...

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

Unknown said...

Problem is this is blocked by a pop up blocker

sathiya said...

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

Gautam said...

thanks , i was looking for the solution


Thiru Travelling said...

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

dhara said...

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

Anonymous said...

Nice! Saved lot of time

Anonymous said...

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

Unknown said...

when click a button two windows will be open

Unknown said...

what is that textbox1 means in the code

Unknown said...

its ID of textbox @Dinesh.P