Category >
ASP.NET
|| Published on :
Monday, October 14, 2019 || Views:
7870
||
Open new tab on LinkButton Click
Introduction
Here Pawan Kumar will explain how to Open new tab on LinkButton Click using C# and VB.Net in ASP.Net
Description
Now I will explain How to Open new tab on LinkButton Click using C# and VB.Net in ASP.Net
So follow the steps to learn Open new tab on LinkButton Click using C# and VB.Net in ASP.Net
Step 1 - Create a asp.net website using Visual Studio 2019 por any other version
Step 2 - Add a new Webform C# into the website created in step 1
Step 3 - Drag and drop link button from visual studio toolbar.
Step 4 - CS.ASPX codes are below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <%@ Page Language= "C#" AutoEventWireup= "true" CodeFile= "CS.aspx.cs" Inherits= "examples_1_CS" %>
<!DOCTYPE html>
<head runat= "server" >
<title></title>
</head>
<body>
<form id= "form1" runat= "server" >
<div>
<asp:LinkButton Text= "Open" runat= "server" ID= "lnk" OnClick= "lnk_Click" />
</div>
</form>
</body>
</html>
|
Step 5: In the code behind file of CS.ASPX add the following codes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class examples_1_CS : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void lnk_Click(object sender, EventArgs e)
{
string Url = "DEMO.aspx" ;
Response.Write( "<script language='javascript'>window.open('" + Url + "','_blank','');" );
Response.Write( "</script>" );
}
}
|
Visual Basic version is also available below
VB.ASPX
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <%@ Page Language= "VB" AutoEventWireup= "false" CodeFile= "VB.aspx.vb" Inherits= "examples_VB" %>
<!DOCTYPE html>
<head runat= "server" >
<title></title>
</head>
<body>
<form id= "form1" runat= "server" >
<div>
<asp:LinkButton Text= "Open" runat= "server" ID= "lnk" OnClick= "lnk_Click" />
</div>
</form>
</body>
</html>
|
Vb.aspx.vb
1 2 3 4 5 6 7 8 9 10 | Partial Class examples_VB
Inherits System.Web.UI.Page
Protected Sub lnk_Click(ByVal sender As Object , ByVal e As EventArgs)
Dim Url As String = "Default.aspx"
Response.Write( "<script language='javascript'>window.open('" & Url & "','_blank','');" )
Response.Write( "</script>" )
End Sub
End Class
|
In this example we have write javascript window open method with url we want to open. The codes in response method we write javascript window open codes
Conclusion:
So, In this tutorial we have learned, Open new tab on LinkButton Click using C# and VB.Net in ASP.Net