To open a new page in a new tab from a hyperlink is an easy thing but from a code behind is not a easy one to do. In this example I will show you how to redirect to a new page from code behind in C#.
First create a new project and add two new pages. page1.aspx and page2.aspx
Now in page1.aspx add two new buttons. In the code behind of two buttons add bellow codes.
Method 1 :
This is to open a page in pop up.
Now in the code behind
Method 2 :
This is to redirect a page in a another tab.
And the code is simpler even.
Download the full source code here. Try it yours...Enjoy.... :)
First create a new project and add two new pages. page1.aspx and page2.aspx
Now in page1.aspx add two new buttons. In the code behind of two buttons add bellow codes.
Method 1 :
This is to open a page in pop up.
<body> <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" Text="Open in Popup" OnClick="Button1_Click" /> </div> </form> </body>
Now in the code behind
/// <summary> /// in pop up/// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click(object sender, EventArgs e) { Page.ClientScript.RegisterStartupScript( this.GetType(), "OpenWindow", "window.open('2.aspx','_newtab');", true); }
Method 2 :
This is to redirect a page in a another tab.
<body> <form id="form1" runat="server"> <div> <asp:Button ID="Button2" runat="server" Text="Open in Other Tab" onclick="Button2_Click" OnClientClick="document.forms[0].target ='_blank';" /> </div> </form> </body>
And the code is simpler even.
/// <summary> /// in other tab /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button2_Click(object sender, EventArgs e) { Response.Redirect("2.aspx"); }
Download the full source code here. Try it yours...Enjoy.... :)
Works for me. Thanks.
ReplyDeletenice example..
ReplyDeleteLearnByGuru
SarkariPost
CrazyClub
This blog is really helpful regarding all educational knowledge I earned. It covered a great area of subject which can assist a lot of needy people. Everything mentioned here is clear and very useful. Computer Graphics Programs
ReplyDeleteWorked like charm :)
ReplyDelete