尝试运行我的ASP.NET程序时,我收到以下错误消息:
编译器错误消息:CS1061:'ASP.about_aspx'不包含'btnRunReports_Click'的定义,并且没有扩展方法'btnRunReports_Click'接受类型'ASP.about_aspx'的第一个参数可以找到(你是否错过了使用指令或程序集引用?)
下面第18行似乎是问题,但我不明白为什么。
Line 16: </p>
第17行:
第18行:<asp:Button ID="btnRunReports" runat="server" Text="Run Reports" onclick="btnRunReports_Click" />
第19行:
<p><asp:Button ID="IdSort" runat="server" Text="Sort" onclick="IdSort_Click" />
在运行报告按钮上,我有以下代码:
protected void btnRunReports_Click(object sender, EventArgs e)
{
RunReport();
}
然后
public void RunReport()
{
Application.Lock();
// lb1 = (SaleList)Application["SaleList"];
TextReportGenerator trg = new TextReportGenerator(saleList);
trg.GenerateAllReport("report.txt");
Application.UnLock();
}
我不知道如何修复此错误,我在该行18上的.cs中没有错误,一些指导将非常感激。
这是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();
}
}
} `
答案 0 :(得分:0)
您的网页指示错误。它必须是这样的:
<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Antiques.About.aspx.cs" Inherits="Antiques.About" %>