名称“___”在当前上下文中不存在

时间:2013-12-19 15:46:32

标签: c# asp.net visual-studio-2012

我似乎在Visual Studio 2012中遇到了我的项目问题,我收到了21个错误,说当前上下文中不存在名称(ddlstud,hidId,txtName,txtCoverImage,txtReldate,gvVidGame)。我将default.aspx文件设置为从default.aspx.cs文件中读取。

这是我的default.aspx文件

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="True" CodeBehind="Default.aspx.cs" Inherits="VideoGameWiki._Default" %>

<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">

</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <asp:GridView ID="gvVidGame" runat="server"></asp:GridView><br />
    <asp:Label ID="lblName" runat="server" Text="Name: "></asp:Label>
    <asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />
    <asp:Label ID="lblStud" runat="server" Text="Studio: "></asp:Label>
    <asp:DropDownList ID="ddlStud" runat="server"></asp:DropDownList><br />
    <asp:Label ID="lblReldate" runat="server" Text="Release date: "></asp:Label>
    <asp:TextBox ID="txtReldate" runat="server"></asp:TextBox><br />
    <asp:Label ID="lblCoverImage" runat="server" Text="Cover Image: "></asp:Label>
    <asp:TextBox ID="txtCoverImage" runat="server"></asp:TextBox><br />
    <asp:Label ID="lblDescr" runat="server" Text="Description: "></asp:Label>
    <asp:TextBox ID="txtDescr" runat="server"></asp:TextBox>
    <br />
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Add" />
    <br />
    <asp:Button ID="btnNext" runat="server" Text="Next" OnClick="btnNext_Click" />
    <input runat="server" id="hidId" type="hidden" />
    <asp:Button ID="btnPrev" runat="server" OnClick="btnPrev_Click" Text="Prev" />
    <asp:Button ID="Btn_delete" runat="server" Text="Delete" />
</asp:Content>

这是我的default.aspx.cs文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace VideoGameWiki
{
    public partial class _Default : System.Web.UI.Page
    {
        private VideoGamesWikiContainer entities = new VideoGamesWikiContainer();

        private int currentId = 0;
    }
}

complete sources here

(编辑)这是我的designer.cs文件,因为建议的方法不幸地不起作用。

 namespace VideoGameWiki {


public partial class _Default : System.Web.UI.Page
{

    /// <summary>
    /// gvVidGame control.
    /// </summary>
    /// <remarks>
    /// Auto-generated field.
    /// To modify move field declaration from designer file to code-behind file.
    /// </remarks>
    protected global::System.Web.UI.WebControls.GridView gvVidGame;

complete sources here

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:7)

差不多一个小时后,它似乎是一个随机错误,通过右键单击项目名称并选择Rebuild解决了错误。 :)