On Button Click How Open A page in new window in asp.net - c# code


Task: Open a new window using c# code in asp.net website/web application. 
Description: The problem is this we can use Response.Redirect() method for redirect/open  new webpage in same window, But how we can open a new page in new window.

So that I use javascript code(alert box) for popup new window in c# code behind file as describe below. I write below code on Button Click Event.

// Dynamic Alert box javascript using c# code in asp.net

 protected void btngeneraterecipt_Click(object sender, EventArgs e)
    {
        try
        {
            string queryString = "billformat.aspx";
            string jquery = "window.open('" + queryString + "');";
            ScriptManager.RegisterStartupScript(this,this.GetType(), "pop", jquery, true);
        }
        catch (Exception ee)
        {
            Label1.Text = ee.Message;
        }
    }

11 comments:

  1. Its totally working! thanks so much! :)

    ReplyDelete
  2. while we use this code, popup blocker blocks. how can we remove the popup blocker???

    ReplyDelete
    Replies
    1. This is a javascript code so that popup will comes.
      It cant block. you can use different approach to do this.

      Delete
  3. plz tell me how to open a new page in new tab..... without using popup..... when i click btn.. it opens new page directly...........means we need not to allow popups...

    ReplyDelete
    Replies
    1. Hi,
      On Button Click I found only this method,On Server Side Coding I cant open page in new tab BUT if you make Link(hyperlink) Then you can open new page in new tab(you can manage link dynamically)... :-)

      Delete
    2. http://www.w3schools.com/html/tryit.asp?filename=tryhtml_link_target

      Delete
    3. Hmm.. you are right as I said previously using hyperlink we can open new page in new tab...
      But I think she want's On Button Click Event using back-end(c#) code...

      Delete
  4. Hi,

    I am using Sandbox solution. In that solution scriptManager is not working.Can U plz suggest another way to achieve.

    Regards
    Jacob

    ReplyDelete
    Replies
    1. I already replied to others, I didn't found any other solution for it yet. From code page I have only this way...

      Delete
  5. avoid popup blocker setting open new popup window in asp.net using C#

    ReplyDelete