Ignora collegamentiHome / Blog

Blog


A simple example that shows how to work the TextBox, Button, and Label in an ASP.NET page

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

<!DOCTYPE html>

<script runat="server">
    protected void Button_Click(object sender, EventArgs e)
    {
        if (TextBoxName.Text!="")
            LabelMessage.Text = "Hello " + TextBoxName.Text;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>ASP.NET Demo: TextBox, Button, Label</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Enter your name
        <asp:TextBox ID="TextBoxName" runat="server"></asp:TextBox> 
        <asp:Button ID="Button" runat="server" Text="Click me" OnClick="Button_Click" />
        <br />
        <br />
        <asp:Label ID="LabelMessage" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>

When the page is loaded for the first time LabelMessage not displays null.
   
When the Button is clicked, the Button_Click method is verified the contents of TexBoxName, if it is not null and contains Lisa for example, the text of LabelMessage is set with the following message: Hello Lisa



Category: ASP.NET