ASP.NET LinkButton Example

LinkButton Example
In this example we see how to use LinkButton control in asp.net. Now create a web form name linkButtonExample.aspx, then add two LinkButton control and one Label control. For first LinkButton control we use this OnClick event for showing message in Label. And for another LinkButton control we use the PostBackUrl property for posted back another page name news.aspx. Here is the source code of LinkButtonExample.aspx and news.aspx page.
LinkButtonExample.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void LinkButton1_Click(object sender, System.EventArgs e) {
        Label1.Text = "Link Button1 clicked.";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>LinkButton Example: how to use LinkButton in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="Crimson"></asp:Label>
        <hr />
        <h3>Simple LinkButton</h3>
        <asp:LinkButton ID="LinkButton1" runat="server" Text="Click Link Button1" OnClick="LinkButton1_Click"></asp:LinkButton>
        <hr />
        <h3>Using PostBackUrl property</h3>
        <asp:LinkButton ID="LinkButton2" runat="server" Text="Go to news page" PostBackUrl="~/news.aspx"></asp:LinkButton>
    </div>
    </form>
</body>
</html>
news.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>News Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>This is news page</h1>
    </div>
    </form>
</body>
</html>


More asp.net examples