I am going to explain how to open a page in a 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();
}
5 comments:
Its opening as pop-up in chrome but works fine with mozilla.. can u plz help me??
Check your browser setting.
Thanks. You just saved my life! :)
thanks great info........love you........
Hey Sanjeet - great post. It worked well for me. I have modified to open a new window in a certain position. I have tried to create a button on the original window to close the new window. I tried the window.close command but it closes the original window instead of the new window. Any suggestions would be appreciated.
Post a Comment