C# 编译器错误消息ASP.NET
尝试运行ASP.NET程序时,我收到以下错误消息: 编译器错误消息:CS1061:“ASP.about\u aspx”不包含“btnRunReports\u Click”的定义,并且没有扩展方法“btnRunReports\u Click”接受类型为“ASP”的第一个参数。可以找到about\u aspx。是否缺少using指令或程序集引用 下面第18行似乎是个问题,但我不知道为什么C# 编译器错误消息ASP.NET,c#,asp.net,C#,Asp.net,尝试运行ASP.NET程序时,我收到以下错误消息: 编译器错误消息:CS1061:“ASP.about\u aspx”不包含“btnRunReports\u Click”的定义,并且没有扩展方法“btnRunReports\u Click”接受类型为“ASP”的第一个参数。可以找到about\u aspx。是否缺少using指令或程序集引用 下面第18行似乎是个问题,但我不知道为什么 Line 16: </p> 然后 public void RunReport()
Line 16: </p>
然后
public void RunReport()
{
Application.Lock();
// lb1 = (SaleList)Application["SaleList"];
TextReportGenerator trg = new TextReportGenerator(saleList);
trg.GenerateAllReport("report.txt");
Application.UnLock();
}
我不知道如何修复此错误,我在.cs中没有错误。就在第18行,请提供一些指导
这是About.aspx.cs
`using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Antiques;
using AntiqueSale;
namespace Antiques
{
public partial class About : System.Web.UI.Page, ISaleManagerUI
{
SaleList saleList;
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!ReferenceEquals(null, Session["ID"]))
{
Sale sale = new Sale((string)Session["ID"], (DateTime)Session["Date"], (string)Session["Location"], (double)Session["Picth Cost"], (int)Session["Num Pitches"],
(bool)Session["Charity"], (string)Session["Charity Name"], (bool)Session["Catering"]);
saleList = (SaleList)Application["SaleList"];
saleList.addSale(sale);
Application["SaleList"] = saleList;
UpdateListbox();
}
}
catch (DuplicateIdException)
{
UpdateListbox();
}
lblerror.Text = null;
}
public void LoadData()
{
try
{
Application.Lock();
SerializeFileHandler sr = new SerializeFileHandler();
Application["Antiques Sale"] = sr.ReadSaleListFromFile("data.dat");
UpdateListbox();
Application.UnLock();
}
catch (FileNotFoundException)
{
lblerror.Text = "Error: Not found, must save first";
}
}
protected void Load_Click(object sender, EventArgs e)
{
LoadData();
}
public void AddData()
{
var response = base.Response;
response.Redirect("Default.aspx", true);
}
protected void btnAddBox_Click(object sender, EventArgs e)
{
AddData();
}
public void getSale()
{
}
public void UpdateListbox()
{
Application.Lock();
lb1.Items.Clear();
saleList = (SaleList)Application["SaleList"];
for (int i = 0; i < saleList.Count(); i++)
{
// ListItem lst1 = new ListItem(lb1.saleList(i).ToString(), i.ToString());
// lst1.Items.Add(lb1);
}
Application.UnLock();
}
protected void lb1_Init(object sender, EventArgs e)
{
UpdateListbox();
}
protected void Delete_Click(object sender, EventArgs e)
{
while (lb1.SelectedIndex != -1)
{
ListItem mySelectedItem = (from ListItem li in lb1.Items where li.Selected == true select li).First();
lb1.Items.Remove(mySelectedItem);
}
}
protected void lb1_SelectedIndexChanged(object sender, EventArgs e)
{
}
public void SaveData()
{
saleList = (SaleList)Application["SaleList"];
if (saleList.Count() != 0)
{
Application.Lock();
SerializeFileHandler sr = new SerializeFileHandler();
sr.WriteSaleListToFile((SaleList)Application["SaleList"], "data.dat");
Application.UnLock();
}
else
{
lblerror.Text = "Error: You need to enter data into the list";
}
}
protected void Save_Click(object sender, EventArgs e)
{
SaveData();
}
protected void IdSort_Click(object sender, EventArgs e)
{
SortData();
}
public void SortData()
{
// var item = lb1.getItem(0);
// var index = item.get_index();
// lb1.reorderItem(item, index - 1);
}
public void RunReport()
{
Application.Lock();
// lb1 = (SaleList)Application["SaleList"];
TextReportGenerator trg = new TextReportGenerator(saleList);
trg.GenerateAllReport("report.txt");
Application.UnLock();
}
protected void btnRunReports_Click(object sender, EventArgs e)
{
RunReport();
}
}
}
`您的页面指令错误。它应该是这样的:
<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Antiques.About.aspx.cs" Inherits="Antiques.About" %>
只是为了好玩。请添加与上述每个代码段相关的文件名,好吗?TY您的aspx标记中有指令吗?只有一件事:您确定aspx代码引用了正确的行为代码吗?请发布类的定义,包括名称空间。我的程序中没有Antiques.About.aspx.cs,我尝试了该代码,它说找不到
<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Antiques.About.aspx.cs" Inherits="Antiques.About" %>