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

Label false property cannot be changed programatically by button click

查看了 this 等页面后,我不明白为什么单击提交按钮时标签文本不会显示在简单的测试页面中。由于文件较短,我把所有的代码都包括进去了,以防后台有什么我没有想到的。

Ctrl+F5 生成的渲染中按下按钮时文本不显示 Visual Studio Express 2015.我哪里做错了? 代码:

<%@ 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;
      }
}

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

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