【发布时间】:2017-10-05 08:11:01
【问题描述】:
由于我是 .NET 编程的新手,我正在尝试制作相同的简单项目,只是为了学习和练习。 但是我在事件处理方面遇到了问题。 在我的页面中,我必须为 textBox(textBox1,textBox2) 一个提交按钮和一个 Label1。 我想要的是,当我单击提交按钮时,标签将显示我在 textBox1 和 textBox2 中输入的文本。 到目前为止,我的代码如下: 对于 onClick 事件
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "You clicked the second button.";
}
和
<form id="form1" runat="server">
<div>
Enter Name: <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
</br></br>
</div>
Enter Surname: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</br></br>
<asp:Button ID="Button1" runat="server" Text="submit" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="Results" BackColor="#CCCCCC" BorderColor="#666666" BorderStyle="Solid" Width="157px"></asp:Label>
</form>
【问题讨论】:
-
显示他们在哪里?如果在标签中这样使用 label1.text="Name:" + textbox1.text +" Surname:" + textbox2.text
-
像这样
string Text1Value=Text1.Value;获取文本框的值
标签: c# asp.net visual-studio