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

Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) 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 is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 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!

boydd_uk 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 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 :)

dhanu sugu said...

when click a button two windows will be open

Dinesh .P said...

what is that textbox1 means in the code

Manoj kumar said...

its ID of textbox @Dinesh.P