-2

标记:

<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="Files.aspx.cs" Inherits="WebModules.Web.Files" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

</head>
<body>
    <form id="form1" method="post" runat="server">
        <asp:Label ID="Status" runat="server" />
    </form>
</body>
</html>

代码背后:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;

namespace WebModules.Web
{
    public partial class Files : System.Web.UI.Page
    {
        private void Page_Load(object sender, EventArgs e)
        {
            Status.Text="Hello";
        }

        private void Page_Init(object sender, EventArgs e)
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);
        }
    }
}

当我在浏览器中运行页面时,标签上没有显示文本“Hello”。

有谁知道为什么这不起作用?

4

3 回答 3

1

您可能想尝试将方法上的访问修饰符从private更改为protected

//I'm assuming that Files is the class of your page, and not just another class. Make sure that your markup inherits from this class
public partial class Files : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Status.Text="Hello";
    }
}
于 2012-08-07T17:46:04.273 回答
0

我将您的标签和页面加载代码复制粘贴到我当前的应用程序中,它显示正常。

做这个:

protected void Page_Load(object sender, EventArgs e)

{
Status.Text="Hello";          
}  

然后将标签 ID 放在您的源代码中:

<asp:Label ID="Status" runat="server" />  
于 2012-08-07T17:56:43.823 回答
0

我已经修好了!我刚刚将属性更改AutoEventWireup="false"AutoEventWireup="true". 现在工作正常

于 2012-08-07T18:04:37.950 回答