如何将变量值加载到标签文本? [英] How do I load variable value to label text?
本文介绍了如何将变量值加载到标签文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。我正在学习ASP.NET(C#)并有一个标签,但我不知道如何加载变量值(受保护的字段 - 数据类型是字符串)来标记文本。
我在default.aspx写了这个
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:Label ID="Label1" Text="Hello, <%= name %>" runat="server" />
及其代码:
and behind code:
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!
推荐答案
<asp:Label ID="Label1" runat="server" />
protected string name = null;
protected void Button1_Click()
{
string temp = this.TextBox1.Text;
Label1.Text = "Hello, " + temp;
}
这篇关于如何将变量值加载到标签文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文