来自ASP.NET应用程序的错误CS1601,但看不出原因

时间:2011-08-03 09:07:25

标签: c# asp.net

我正在通过本教程here处理有关进度对话的问题,但遇到了一个基本问题,我无法看到原因。到目前为止,我的项目返回错误消息......

Compiler Error Message: CS1061: 'ASP.webprogressbar_aspx' does not contain a
definition for 'Button1_Click' and no extension method 'Button1_Click' accepting
a first argument of type 'ASP.webprogressbar_aspx' could be found (are you
missing a using directive or an assembly reference?)

Source Error:

Line 12:     <legend>WebProgressBar</legend>
Line 13:     <div>
Line 14:       <asp:Button id="Button1"
Line 15:                   runat="server"
Line 16:                   Text="Start Long Task!"

到目前为止,该项目(完整地)是WebProgressBar.aspx

<%@ Page Language="C#"
         AutoEventWireup="true"
         CodeBehind="WebProgressBar.aspx.cs"%>
<html>
<head id="Head1" runat="server">
<title> </title>
</head>
<body>
<form id="form1" runat="server">
  <fieldset>
   <legend>WebProgressBar</legend>
    <div>
      <asp:Button id="Button1"
                  runat="server"
                  Text="Start Long Task!"
                  OnClick="Button1_Click">
      </asp:Button>
    </div>
  </fieldset>
</form>
</body>
</html>

和WebProgressBar.aspx.cs ......

using System;

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

    public void Button1_Click(object sender, EventArgs e)
    {
        Session["State"] = 1;
    }

}

任何人都可以看到我忽略了什么吗?

2 个答案:

答案 0 :(得分:2)

我认为您错过了Inherits声明中的<%@ Page属性。

<%@ Page ... Inherits="WebProgressBar" %>

答案 1 :(得分:1)

您似乎缺少继承类的标记。基本上它找不到按钮的事件处理程序,因为该类尚未列出。

<%@ Page Language="C#" AutoEventWireup="true" Inherits="WebProgressBar" CodeBehind="WebProgressBar.aspx.cs"%>