ASP.NET C# write value in text box to a label: beginner simple

Justin picture Justin · Sep 14, 2012 · Viewed 41k times · Source

I am trying to find a very simple example for the syntax to simple write the value entered into a text box, and place that value into a label onclick. As basic as it can get I suppose. I only mentioned asp.net because I would like to do that with an aspx page. Thanks!

Answer

Mutu Yolbulan picture Mutu Yolbulan · Sep 14, 2012

in the aspx page

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

and in the cs file

protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = TextBox1.Text;
        }