无法通过按钮单击以编程方式更改标签false属性

时间:2015-11-08 17:58:48

标签: c# asp.net label

浏览了this这样的页面时,我无法理解为什么单击提交按钮时标签文本不会显示在简单的测试页面中。由于文件很短,我已经包含了所有编码,以防万一我在后台没有想到。

在Visual Studio Express 2015中使用 Ctrl + F5 生成的渲染中按下按钮时,不显示文本。我哪里出错了? 代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="labelTest2.aspx.cs"
 Inherits="contact_labelTest2" %>

 <!DOCTYPE html>

 <html xmlns="http://www.w3.org/1999/xhtml">
 <head runat="server">
    <title>Label Test</title>
 </head>
<body>
    <form id="form1" runat="server">
    <div>
       <asp:Button ID="Button1" runat="server" Text="Send"/>
      <asp:Label ID="lblMessage" runat="server" Visible="false">
       Test M AFTERessage</asp:Label>         
    </div>
    </form>
   </body>
  </html>

代码背后:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class contact_labelTest2 : System.Web.UI.Page
{
      protected void Page_Load(object sender, EventArgs e)
      {

      }
      protected void Button1_Click(object sender, EventArgs e)
      {
             lblMessage.Visible = true;
      }
}

1 个答案:

答案 0 :(得分:1)

您还应该将OnClick事件添加到Button。像这样:

<asp:Button ID="Button1" runat="server" Text="Send" OnClick="Button1_Click"/>
相关问题