我刚刚接手了几年前最近触及的C#/ .NET项目,其任务是更新它并包含更多功能。我没有使用该平台的经验,所以我很难解决这个错误。
系统目前正在运行(并且可以正常运行),但是我已经在我的机器上运行了一个副本,并且出现了以下错误,我似乎无法弄清楚它是否已启动并运行:
Compiler Error Message: CS0120: An object reference is required for the non-static field, method, or property '<ProjectName>.<PageName>.System'
Source Error:
Line 195:
Line 196: private static System.Reflection.MethodInfo @__PageInspector_LoadHelper(string helperName) {
Line 197: System.Type helperClass = System.Type.GetType("Microsoft.VisualStudio.Web.PageInspector.Runtime.WebForms.TraceHelpers, Microsoft" +
Line 198: ".VisualStudio.Web.PageInspector.Tracing, Version=2.0.0.0, Culture=neutral, Publi" +
Line 199: "cKeyToken=b03f5f7f11d50a3a", false, false);
我已经从其他问题中确定,当使用非静态字段和方法错误地使用this或this时,通常会导致此错误,但在我的情况下,它似乎来自一个临时文件,我无法控制?
更新:Admin.aspx文件位于:
<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="false"
EnableEventValidation="false" CodeBehind="Admin.aspx.cs" Inherits="CallLog.Admin" %>
<asp:Content ID="Content1" ContentPlaceHolderID="AdminContent1" runat="server">
<div id="System" class="SectionTitle" runat="server">
<table cellpadding="1px" cellspacing="1px">
<tr>
<td class="SectionTitleTd">
<i>SYSTEM</i>
</td>
</tr>
</table>
</div>
<table>
<tr>
<td>
<asp:TextBox ID="txtAddAppSystem" runat="server" Width="200px"></asp:TextBox>
<asp:Button ID="btnAddAppSystem" CssClass="Save" runat="server" Text="Add New System"
OnClick="btnAddAppSystem_Click" ValidationGroup="appsystem" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ValidationGroup="appsystem" ControlToValidate="txtAddAppSystem" ErrorMessage="Please Add System" CssClass="Warning"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="gvAppSystem" runat="server" AutoGenerateColumns="False" AlternatingRowStyle-BackColor="White"
BorderColor="Gray" DataKeyNames="AppSystemId" OnRowCancelingEdit="gvAppSystem_RowCancelingEdit"
OnRowEditing="gvAppSystem_RowEditing" OnRowUpdating="gvAppSystem_RowUpdating">
<AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="true" ShowCancelButton="true"
ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="appSystemId" HeaderText="ID" ReadOnly="true" Visible="false" />
<asp:TemplateField HeaderText="System" ItemStyle-Width="150px">
<ItemTemplate>
   
<%# Eval("appSystemDesc")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtAppSystem" Text='' value='<%# Eval ("appSystemDesc") %>' />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="AdminContent2" runat="server">
<div id="Div1" class="SectionTitle" runat="server">
<table cellpadding="1px" cellspacing="1px">
<tr>
<td class="SectionTitleTd">
<i>STATUS</i>
</td>
</tr>
</table>
</div>
<table>
<tr>
<td>
<asp:TextBox ID="txtAddStatus" runat="server" Width="200px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ValidationGroup="status" runat="server" ControlToValidate="txtAddStatus" ErrorMessage="Please Add Status" CssClass="Warning"></asp:RequiredFieldValidator>
<asp:Button ID="btnAddStatus" CssClass="Save" runat="server" ValidationGroup="status" Text="Add New Status"
OnClick="btnAddStatus_Click" />
</td>
</tr>
<tr>
<td>
<asp:GridView ID="gvStatus" runat="server" AutoGenerateColumns="False" AlternatingRowStyle-BackColor="White"
BorderColor="Gray" DataKeyNames="statusId" OnRowCancelingEdit="gvStatus_RowCancelingEdit"
OnRowEditing="gvStatus_RowEditing" OnRowUpdating="gvStatus_RowUpdating">
<AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="true" ShowCancelButton="true"
ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="statusId" HeaderText="ID" ReadOnly="true" Visible="false" />
<asp:TemplateField HeaderText="Status" ItemStyle-Width="150px">
<ItemTemplate>
   
<%# Eval("statusDesc") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtStatus" Text='' value='<%# Eval ("statusDesc") %>' />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="AdminContent3" runat="server">
<div id="Jurisdiction" class="SectionTitle" runat="server">
<table cellpadding="1px" cellspacing="1px">
<tr>
<td class="SectionTitleTd">
<i>JURISDICTION</i>
</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>
<asp:TextBox ID="txtAddJurisdiction" runat="server" Width="200px"></asp:TextBox>
<asp:Button ID="btnAddJurisdiction" CssClass="Save" runat="server" ValidationGroup="juridiction" Text="Add New Jurisdiction"
OnClick="btnAddJurisdiction_Click" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ValidationGroup="juridiction" ControlToValidate="txtAddJurisdiction" ErrorMessage="Please Add Juridiction" CssClass="Warning"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="gvJurisdiction" runat="server" AutoGenerateColumns="False" AlternatingRowStyle-BackColor="White"
BorderColor="Gray" DataKeyNames="jurisdictionId" OnRowCancelingEdit="gvJurisdiction_RowCancelingEdit"
OnRowEditing="gvJurisdiction_RowEditing" OnRowUpdating="gvJurisdiction_RowUpdating">
<AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="true" ShowCancelButton="true"
ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="jurisdictionId" HeaderText="ID" ReadOnly="true" Visible="false" />
<asp:TemplateField HeaderText="Jurisdiction" ItemStyle-Width="150px">
<ItemTemplate>
   
<%# Eval("jurisdictionDesc") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtJurisdiction" Text='' value='<%# Eval ("jurisdictionDesc") %>' />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="AdminContent4" runat="server">
<div id="Impact" class="SectionTitle" runat="server">
<table cellpadding="1px" cellspacing="1px">
<tr>
<td class="SectionTitleTd">
<i>IMPACT</i>
</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>
<asp:TextBox ID="txtImpact" runat="server" Width="200px"></asp:TextBox>
<asp:Button ID="btnImpact" CssClass="Save" runat="server" Text="Add New Impact" ValidationGroup="impact" OnClick="btnAddImpact_Click" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtImpact" ValidationGroup="impact" ErrorMessage="Please Add Impact" CssClass="Warning"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="gvImpact" runat="server" AutoGenerateColumns="False" AlternatingRowStyle-BackColor="White"
BorderColor="Gray" DataKeyNames="impactId" OnRowCancelingEdit="gvImpact_RowCancelingEdit"
OnRowEditing="gvImpact_RowEditing" OnRowUpdating="gvImpact_RowUpdating">
<AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="true" ShowCancelButton="true"
ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="impactId" HeaderText="ID" ReadOnly="true" Visible="false" />
<asp:TemplateField HeaderText="Impact" ItemStyle-Width="150px">
<ItemTemplate>
   
<%# Eval("impactDesc") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtImpact" Text='' value='<%# Eval ("impactDesc") %>' />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="AdminContent5" runat="server">
<div id="Period" class="SectionTitle" runat="server">
<table cellpadding="1px" cellspacing="1px">
<tr>
<td class="SectionTitleTd">
<i>PERIOD</i>
</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>
<asp:TextBox ID="txtAddPeriod" runat="server" Width="200px"></asp:TextBox>
<asp:Button ID="btnAddPeriod" CssClass="Save" runat="server" ValidationGroup="period" Text="Add New Period"
OnClick="btnAddPeriod_Click" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ValidationGroup="period" ControlToValidate="txtAddPeriod" ErrorMessage="Please Add Period" CssClass="Warning"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="gvPeriod" runat="server" AutoGenerateColumns="False" AlternatingRowStyle-BackColor="White"
BorderColor="Gray" DataKeyNames="periodId" OnRowCancelingEdit="gvPeriod_RowCancelingEdit"
OnRowEditing="gvPeriod_RowEditing" OnRowUpdating="gvPeriod_RowUpdating">
<AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="true" ShowCancelButton="true"
ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="periodId" HeaderText="ID" ReadOnly="true" Visible="false" />
<asp:TemplateField HeaderText="Period" ItemStyle-Width="150px">
<ItemTemplate>
   
<%# Eval("periodDesc") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtPeriod" Text='' value='<%# Eval ("periodDesc") %>' />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="AdminContent6" runat="server">
<div id="Issue" class="SectionTitle" runat="server">
<table cellpadding="1px" cellspacing="1px">
<tr>
<td class="SectionTitleTd">
<i>ISSUE</i>
</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>
<asp:TextBox ID="txtAddIssue" runat="server" Width="200px"></asp:TextBox>
<asp:Button ID="btnAddIssue" CssClass="Save" runat="server" ValidationGroup="issue" Text="Add New Issue"
OnClick="btnAddIssue_Click" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ValidationGroup="issue" ControlToValidate="txtAddIssue" ErrorMessage="Please Add Issue" CssClass="Warning"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="gvIssue" runat="server" AutoGenerateColumns="False" AlternatingRowStyle-BackColor="White"
BorderColor="Gray" DataKeyNames="issueId" OnRowCancelingEdit="gvIssue_RowCancelingEdit"
OnRowEditing="gvIssue_RowEditing" OnRowUpdating="gvIssue_RowUpdating">
<AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="true" ShowCancelButton="true"
ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="issueId" HeaderText="ID" ReadOnly="true" Visible="false" />
<asp:TemplateField HeaderText="Issue" ItemStyle-Width="150px">
<ItemTemplate>
   
<%# Eval("issueDesc")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtIssue" Text='' value='<%# Eval ("issueDesc") %>' />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</asp:Content>
更新2:下面的Admin.aspx.cs文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Midtier.DAL;
namespace CallLog
{
public partial class Admin : System.Web.UI.Page
{
AdminDisplay ad = new AdminDisplay();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
listJurisdictions();
listImpact();
listStatus();
listPeriod();
listAppSystem();
listIssue();
}
}
#region AppSystem
public void listAppSystem()
{
gvAppSystem.DataSource = ad.getAppSystem();
gvAppSystem.DataBind();
}
protected void gvAppSystem_RowEditing(object sender, GridViewEditEventArgs e)
{
btnAddAppSystem.Enabled = false;
gvAppSystem.EditIndex = e.NewEditIndex;
listAppSystem();
}
protected void gvAppSystem_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
e.Cancel = true;
gvAppSystem.EditIndex = -1;
listAppSystem();
}
protected void gvAppSystem_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = gvAppSystem.Rows[e.RowIndex];
TextBox txtAppSystemDesc = (TextBox)row.FindControl("txtAppSystem");
int appSystemID = Int32.Parse(gvAppSystem.DataKeys[e.RowIndex].Value.ToString());
string appSystemDesc = txtAppSystemDesc.Text;
AdminUpdates au = new AdminUpdates();
au.AddEditAppSystem(appSystemID, appSystemDesc);
gvAppSystem.EditIndex = -1;
listAppSystem();
btnAddAppSystem.Enabled = true;
}
protected void btnAddAppSystem_Click(object sender, EventArgs e)
{
AdminUpdates au = new AdminUpdates();
au.AddEditAppSystem(-1, txtAddAppSystem.Text);
listAppSystem();
txtAddStatus.Text = "";
}
#endregion
#region Status
public void listStatus()
{
gvStatus.DataSource = ad.getStatus();
gvStatus.DataBind();
}
protected void gvStatus_RowEditing(object sender, GridViewEditEventArgs e)
{
btnAddStatus.Enabled = false;
gvStatus.EditIndex = e.NewEditIndex;
listStatus();
}
protected void gvStatus_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
e.Cancel = true;
gvStatus.EditIndex = -1;
listStatus();
}
protected void gvStatus_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = gvStatus.Rows[e.RowIndex];
TextBox txtStatusDesc = (TextBox)row.FindControl("txtStatus");
int statusID = Int32.Parse(gvStatus.DataKeys[e.RowIndex].Value.ToString());
string statusDesc = txtStatusDesc.Text;
AdminUpdates au = new AdminUpdates();
au.AddEditStatus(statusID, statusDesc);
gvStatus.EditIndex = -1;
listStatus();
btnAddStatus.Enabled = true;
}
protected void btnAddStatus_Click(object sender, EventArgs e)
{
AdminUpdates au = new AdminUpdates();
au.AddEditStatus(-1, txtAddStatus.Text);
listStatus();
txtAddStatus.Text = "";
}
#endregion
#region Jurisdiction
private void listJurisdictions()
{
gvJurisdiction.DataSource = ad.getJurisdiction();
gvJurisdiction.DataBind();
}
protected void gvJurisdiction_RowEditing(object sender, GridViewEditEventArgs e)
{
btnAddJurisdiction.Enabled = false;
gvJurisdiction.EditIndex = e.NewEditIndex;
listJurisdictions();
}
protected void gvJurisdiction_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
e.Cancel = true;
gvJurisdiction.EditIndex = -1;
listJurisdictions();
}
protected void gvJurisdiction_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = gvJurisdiction.Rows[e.RowIndex];
TextBox txtJurisdictionDesc = (TextBox)row.FindControl("txtJurisdiction");
int jurisdictionID = Int32.Parse(gvJurisdiction.DataKeys[e.RowIndex].Value.ToString());
string jurisdictionDesc = txtJurisdictionDesc.Text;
AdminUpdates au = new AdminUpdates();
au.AddEditJurisdiction(jurisdictionID, jurisdictionDesc);
gvJurisdiction.EditIndex = -1;
listJurisdictions();
btnAddJurisdiction.Enabled = true;
}
protected void btnAddJurisdiction_Click(object sender, EventArgs e)
{
AdminUpdates au = new AdminUpdates();
au.AddEditJurisdiction(-1, txtAddJurisdiction.Text);
listJurisdictions();
txtAddJurisdiction.Text = "";
}
#endregion
#region Impact
private void listImpact()
{
gvImpact.DataSource = ad.getImpact();
gvImpact.DataBind();
}
protected void gvImpact_RowEditing(object sender, GridViewEditEventArgs e)
{
btnImpact.Enabled = false;
gvImpact.EditIndex = e.NewEditIndex;
listImpact();
}
protected void gvImpact_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
e.Cancel = true;
gvImpact.EditIndex = -1;
listImpact();
}
protected void gvImpact_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = gvImpact.Rows[e.RowIndex];
TextBox txtImpactDesc = (TextBox)row.FindControl("txtImpact");
int impactID = Int32.Parse(gvImpact.DataKeys[e.RowIndex].Value.ToString());
string impactDesc = txtImpactDesc.Text;
AdminUpdates au = new AdminUpdates();
au.AddEditImpact(impactID, impactDesc);
gvImpact.EditIndex = -1;
listImpact();
btnImpact.Enabled = true;
}
protected void btnAddImpact_Click(object sender, EventArgs e)
{
AdminUpdates au = new AdminUpdates();
au.AddEditImpact(-1, txtImpact.Text);
listImpact();
txtImpact.Text = "";
}
#endregion
#region Period
private void listPeriod()
{
gvPeriod.DataSource = ad.getPeriod();
gvPeriod.DataBind();
}
protected void gvPeriod_RowEditing(object sender, GridViewEditEventArgs e)
{
btnAddPeriod.Enabled = false;
gvPeriod.EditIndex = e.NewEditIndex;
listPeriod();
}
protected void gvPeriod_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
e.Cancel = true;
gvPeriod.EditIndex = -1;
listPeriod();
}
protected void gvPeriod_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = gvPeriod.Rows[e.RowIndex];
TextBox txtPeriodDesc = (TextBox)row.FindControl("txtPeriod");
int periodID = Int32.Parse(gvPeriod.DataKeys[e.RowIndex].Value.ToString());
string periodDesc = txtPeriodDesc.Text;
AdminUpdates au = new AdminUpdates();
au.AddEditPeriod(periodID, periodDesc);
gvPeriod.EditIndex = -1;
listPeriod();
btnAddPeriod.Enabled = true;
}
protected void btnAddPeriod_Click(object sender, EventArgs e)
{
AdminUpdates au = new AdminUpdates();
au.AddEditPeriod(-1, txtAddPeriod.Text);
listPeriod();
txtAddPeriod.Text = "";
}
#endregion
#region Issue
private void listIssue()
{
gvIssue.DataSource = ad.getIssue();
gvIssue.DataBind();
}
protected void gvIssue_RowEditing(object sender, GridViewEditEventArgs e)
{
btnAddIssue.Enabled = false;
gvIssue.EditIndex = e.NewEditIndex;
listIssue();
}
protected void gvIssue_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
e.Cancel = true;
gvIssue.EditIndex = -1;
listIssue();
}
protected void gvIssue_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = gvIssue.Rows[e.RowIndex];
TextBox txtIssueDesc = (TextBox)row.FindControl("txtIssue");
int issueID = Int32.Parse(gvIssue.DataKeys[e.RowIndex].Value.ToString());
string issueDesc = txtIssueDesc.Text;
AdminUpdates au = new AdminUpdates();
au.AddEditIssue(issueID, issueDesc);
gvIssue.EditIndex = -1;
listIssue();
btnAddIssue.Enabled = true;
}
protected void btnAddIssue_Click(object sender, EventArgs e)
{
AdminUpdates au = new AdminUpdates();
au.AddEditIssue(-1, txtAddIssue.Text);
listIssue();
txtAddIssue.Text = "";
}
#endregion
}
}
答案 0 :(得分:0)
通常情况下,我找到了解决我自己问题的方法(两杯咖啡和八小时的睡眠时间 - 不按顺序)。
问题是在Admin.aspx
中,第一个div
id=System
强制Admin.aspx.designer.cs
文件生成名为System.Web.UI.HtmlControls.HtmlGenericControl
的{{1}}变量
由于System
命名空间,这对编译器造成了某种混淆(即使是实际的东西?)。
对于不该做的事情,这是一个很好的教训。