【问题标题】:Events in .NET OnClick button i want to show me some txt enterent in a previous textBox.NET OnClick 按钮中的事件我想向我展示在上一个文本框中输入的一些文本
【发布时间】: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" />
    &nbsp;&nbsp;&nbsp;

    <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


【解决方案1】:

您要查找的代码是:

protected void Button2_Click(object sender, EventArgs e)
    {

        Label1.Text = TextBox1.Text + " " + TextBox2.Text;
    }

C# 尤其是 WPF 是非常面向对象的。因此,您应该将所有内容视为可以与之交互的对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多