-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(オブジェクト送信者, EventArgs e)

{
Status.Text="Hello";          
}  

次に、Label ID をソース コードに配置します。

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

私はそれを修正しました!属性AutoEventWireup="false"を に変更しましたAutoEventWireup="true"。今はうまくいきます

于 2012-08-07T18:04:37.950 に答える