Mazen Elkashef
Mazen Elkashef

Reputation: 3499

How to make the button_Click event opens the page in a pop-up window in ASP.NET?

The question is simple but I can't find a simple answer to it! .. btw I'll need to pass a QueryString to the page to be open.

Any ideas ?

Upvotes: 1

Views: 5502

Answers (3)

Kirk
Kirk

Reputation: 16255

It depends on what you're trying to do but the simplest is to use the OnClientClick property of the Button. Take a look at http://msdn.microsoft.com/en-us/library/7ytf5t7k.aspx, in particular the details bout this property a little bit down.

Basically you'd do something like

<asp:Button ID="Button1" Runat="server" 
        OnClientClick="ShowPopup();" 
        Text="Test Client Click" />

With the JS to do your popup

<script type="text/javascript">
    function ShowPopup() {
        window.open('ThankYou.aspx');
    }
</script>

You can also do both an OnClientClick and an OnClick if you need as well.

<asp:Button ID="Button1" Runat="server" 
      OnClick="Button1_Click" 
        OnClientClick="ShowPopup();" 
        Text="Test Client Click" />

Code behind

    protected void Button1_Click(Object sender, EventArgs e)
    {
        Label1.Text = "Server click handler called.";
    }

Upvotes: 1

C0L.PAN1C
C0L.PAN1C

Reputation: 12243

You can actually link a javascript code into .NET with C#, below is an example, you could replace with your info, and push the parameters.

   Response.Write("<script type='text/javascript'>window.open('Page.aspx?ID=" + YourTextField.Text.ToString() + "','_blank');</script>");

You can append on the end of it ?Field=your value passing&nextField=another value.

Upvotes: 1

akc42
akc42

Reputation: 5001

Is the answer to do this in javascript. As you make the underlying page in asp.net, provide it with the javascript to catch the buttons onclick event and call window.open(URL)

Upvotes: 1

Related Questions