【发布时间】:2014-08-21 21:28:14
【问题描述】:
在尝试运行我的 ASP.NET 程序时,我收到以下错误消息:
编译器错误消息:CS1061:“ASP.about_aspx”不包含“btnRunReports_Click”的定义,并且找不到接受“ASP.about_aspx”类型的第一个参数的扩展方法“btnRunReports_Click”(您是否缺少使用指令还是程序集引用?)
下面的第 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();
}
}
} `
【问题讨论】:
-
只是为了好玩。您能否添加与上述每个代码 sn-ps 关联的文件名? ty
-
你的 aspx 标记中有 指令吗?
-
只有一件事:你确定aspx代码是否引用了正确的行为代码?
-
-
请贴出类的定义,包括命名空间。