asp.net - How to change LinkButton text programmatically

Set or change LinkButton text programmatically
LinkButton is an asp.net web server control. this control render as a hyperlink-style submit button on web page. by default a linkbutton control is a submit button. linkbutton control have a built in property to set or change its text programmatically at run time.

linkbutton Text property get or set the text caption displayed on the linkbutton server control. so we can change the linkbutton text by setting its Text property dynamically at run time. this property value type is System.String. this 'String' represents the text caption displayed on the linkbutton control. this property default value is empty string.

the following asp.net c# example code demonstrate us how can we set or change linkbutton text programmatically at run time in an asp.net application.
LinkButtonText.aspx
<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        LinkButton1.Text = "Login";
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        LinkButton1.Text = "Logout";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change LinkButton text programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Green">LinkButton Example: Text</h2>
        <asp:LinkButton 
             ID="LinkButton1" 
             runat="server"
             Text="LinkButton Text Test"
             Height="25"
             ForeColor="Tomato"
             Font-Bold="true"
             Font-Size="Large"
             >
        </asp:LinkButton>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="IndianRed"
             Text="LinkButton Text Login"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server"
             ForeColor="IndianRed"
             Text="LinkButton Text Logout"
             Height="45"
             OnClick="Button2_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>








Related asp.net example