Thursday, 15 November 2012

Response.Redirect Open Page In New Tab/Window


Response.Redirect Open Page In New Tab/Window


I am going to explain how to open new tab/window on Button click in asp.net. Suppose the page contains a button called "btnTest" and your requirement is open a specified page in the new tab on the button click then do the following.

<asp:Button ID=”btnTest” runat=”Server” Text=”Test” OnClick=”btnTest_Click”

OnClientClick ="document.forms[0].target = '_blank';"/>

protected void btnTest_Click(object sender, EventArgs e)

{

      Response.Redirect(”New.aspx”);

}


OR

If there is some code to execute on button click and after that you want to open the page in new tab then do the following :

protected void btnTest_Click(object sender, EventArgs e)

{

      .

      .         // Your Code Here

      .

      Response.Write( <script> window.open( New.aspx,'_blank' ); </script>);

      Response.End();

}


OR

If you want to open the page in a new tab as well as pass some values to the specified page using querystring then do the following :


protected void btnTest_Click(object sender, EventArgs e)

{

      .

      .

      .

      string pageurl="Default.aspx?Id=6&RollNo=15";

      Response.Write( <script> window.open( "+pageurl+",'_blank' ); </script>);

      Response.End();

}

4 comments:

  1. dear vishal
    i have a linkbutton inside gridview .here i need that ,
    when i click on that link button it will open a new tab with taking the commad_argument data of linkbutton in query string
    i have used the above code but it is not working.
    will you please help me for this issue

    thank you

    ReplyDelete
  2. Refer these links:

    http://forums.asp.net/p/1957498/5587458.aspx?Open+a+new+aspx+page+in+new+window

    http://www.aspforums.net/Threads/414279/How-to-open-Popup-Window-on-click-of-Link-Button-inside-GridView-in-ASPNet/

    ReplyDelete
  3. Awesome tips. Thanks for share useful information.

    ReplyDelete

Thank You for Your Comments. We will get back to you soon.

back to top