Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. I'm learning at ASP.NET (C#) and have a label, but I don't know how to load the variable value (protected field - data type is string) to label text.

I wrote this in default.aspx
ASP.NET
<asp:Label ID="Label1" Text="Hello, <%= name %>" runat="server" />


and behind code:
C#
protected string name = null;

protected void Button1_Click()
{
string temp = this.TextBox1.Text;
this.name = temp;
}


But it doesn't work and I don't know why.

Can you give me anyway to fix it?

Thank you!
Posted

1 solution

XML
<asp:Label ID="Label1" runat="server" />


CSS
protected string name = null;

protected void Button1_Click()
{
    string temp = this.TextBox1.Text;
    Label1.Text = "Hello, " + temp;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900