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

发布于 2024-08-18 00:22:32 字数 5703 浏览 3 评论 0原文

我有两个名为 TimeSheet.aspx.cs 和 TimSheet.aspx 的文件,下面给出文件的代码供您参考。

当我构建应用程序时,我收到错误“名称'GridView1'在当前上下文中不存在”,即使我有一个ID为GridView1的控件,并且我也添加了runat =“server”。

我无法弄清楚是什么导致了这个问题。任何人都可以弄清楚这里发生了什么吗?

谢谢&问候,

=======================================
TimeSheet.aspx.cs 
=======================================
#region Using directives
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TSMS.Web.UI;
#endregion

public partial class TimeSheets: Page
{   
    protected void Page_Load(object sender, EventArgs e)
    {

        FormUtil.RedirectAfterUpdate(GridView1, "TimeSheets.aspx?page={0}");
        FormUtil.SetPageIndex(GridView1, "page");
        FormUtil.SetDefaultButton((Button)GridViewSearchPanel1.FindControl("cmdSearch"));
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string urlParams = string.Format("TimeSheetId={0}", GridView1.SelectedDataKey.Values[0]);
        Response.Redirect("TimeSheetsEdit.aspx?" + urlParams, true);
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {


    }
}
=======================================================
TimeSheet.aspx
=======================================================
<%@ Page Language="C#" Theme="Default" MasterPageFile="~/MasterPages/admin.master" AutoEventWireup="true"  CodeFile="TimeSheets.aspx.cs" Inherits="TimeSheets" Title="TimeSheets List" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">Time Sheets List</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <data:GridViewSearchPanel ID="GridViewSearchPanel1" runat="server" GridViewControlID="GridView1" PersistenceMethod="Session" />
        <br />
        <data:EntityGridView ID="GridView1" runat="server"          
                AutoGenerateColumns="False"                 
                OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
                DataSourceID="TimeSheetsDataSource"
                DataKeyNames="TimeSheetId"
                AllowMultiColumnSorting="false"
                DefaultSortColumnName="" 
                DefaultSortDirection="Ascending"    
                ExcelExportFileName="Export_TimeSheets.xls" onrowcommand="GridView1_RowCommand"         
            >
            <Columns>
                <asp:CommandField ShowSelectButton="True" ShowEditButton="True" />              
                <asp:BoundField DataField="TimeSheetId" HeaderText="Time Sheet Id" SortExpression="[TimeSheetID]" ReadOnly="True" />
                <asp:BoundField DataField="TimeSheetTitle" HeaderText="Time Sheet Title" SortExpression="[TimeSheetTitle]"  />
                <asp:BoundField DataField="StartDate" DataFormatString="{0:d}" HtmlEncode="False" HeaderText="Start Date" SortExpression="[StartDate]"  />
                <asp:BoundField DataField="EndDate" DataFormatString="{0:d}" HtmlEncode="False" HeaderText="End Date" SortExpression="[EndDate]"  />
                <asp:BoundField DataField="DateOfCreation" DataFormatString="{0:d}" HtmlEncode="False" HeaderText="Date Of Creation" SortExpression="[DateOfCreation]"  />
                <data:BoundRadioButtonField DataField="Locked" HeaderText="Locked" SortExpression="[Locked]"  />
                <asp:BoundField DataField="ReviewedBy" HeaderText="Reviewed By" SortExpression="[ReviewedBy]"  />
                <data:HyperLinkField HeaderText="Employee Id" DataNavigateUrlFormatString="EmployeesEdit.aspx?EmployeeId={0}" DataNavigateUrlFields="EmployeeId" DataContainer="EmployeeIdSource" DataTextField="LastName" />

            </Columns>
            <EmptyDataTemplate>
                <b>No TimeSheets Found!</b>
            </EmptyDataTemplate>
        </data:EntityGridView>
        <asp:GridView ID="GridView2" runat="server">
    </asp:GridView>
        <br />
        <asp:Button runat="server" ID="btnTimeSheets" OnClientClick="javascript:location.href='TimeSheetsEdit.aspx'; return false;" Text="Add New"></asp:Button>
        <data:TimeSheetsDataSource ID="TimeSheetsDataSource" runat="server"
            SelectMethod="GetPaged"
            EnablePaging="True"
            EnableSorting="True"
            EnableDeepLoad="True"
            >
            <DeepLoadProperties Method="IncludeChildren" Recursive="False">
                <Types>
                    <data:TimeSheetsProperty Name="Employees"/> 
                    <%--<data:TimeSheetsProperty Name="TimeSheetDetailsCollection" />--%>
                </Types>
            </DeepLoadProperties>
            <Parameters>
                <data:CustomParameter Name="WhereClause" Value="" ConvertEmptyStringToNull="false" />
                <data:CustomParameter Name="OrderByClause" Value="" ConvertEmptyStringToNull="false" />
                <asp:ControlParameter Name="PageIndex" ControlID="GridView1" PropertyName="PageIndex" Type="Int32" />
                <asp:ControlParameter Name="PageSize" ControlID="GridView1" PropertyName="PageSize" Type="Int32" />
                <data:CustomParameter Name="RecordCount" Value="0" Type="Int32" />
            </Parameters>
        </data:TimeSheetsDataSource>

</asp:Content>

I have two files named as TimeSheet.aspx.cs and TimSheet.aspx ,code of the file are given below for your reference.

when i build the application im getting error "The name 'GridView1' does not exist in the current context" even thought i have a control with the id GridView1 and i have added the runat="server" as well.

Im not able to figure out what is causing this issue.Can any one figure whats happen here.

Thanks & Regards,

=======================================
TimeSheet.aspx.cs 
=======================================
#region Using directives
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TSMS.Web.UI;
#endregion

public partial class TimeSheets: Page
{   
    protected void Page_Load(object sender, EventArgs e)
    {

        FormUtil.RedirectAfterUpdate(GridView1, "TimeSheets.aspx?page={0}");
        FormUtil.SetPageIndex(GridView1, "page");
        FormUtil.SetDefaultButton((Button)GridViewSearchPanel1.FindControl("cmdSearch"));
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string urlParams = string.Format("TimeSheetId={0}", GridView1.SelectedDataKey.Values[0]);
        Response.Redirect("TimeSheetsEdit.aspx?" + urlParams, true);
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {


    }
}
=======================================================
TimeSheet.aspx
=======================================================
<%@ Page Language="C#" Theme="Default" MasterPageFile="~/MasterPages/admin.master" AutoEventWireup="true"  CodeFile="TimeSheets.aspx.cs" Inherits="TimeSheets" Title="TimeSheets List" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">Time Sheets List</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <data:GridViewSearchPanel ID="GridViewSearchPanel1" runat="server" GridViewControlID="GridView1" PersistenceMethod="Session" />
        <br />
        <data:EntityGridView ID="GridView1" runat="server"          
                AutoGenerateColumns="False"                 
                OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
                DataSourceID="TimeSheetsDataSource"
                DataKeyNames="TimeSheetId"
                AllowMultiColumnSorting="false"
                DefaultSortColumnName="" 
                DefaultSortDirection="Ascending"    
                ExcelExportFileName="Export_TimeSheets.xls" onrowcommand="GridView1_RowCommand"         
            >
            <Columns>
                <asp:CommandField ShowSelectButton="True" ShowEditButton="True" />              
                <asp:BoundField DataField="TimeSheetId" HeaderText="Time Sheet Id" SortExpression="[TimeSheetID]" ReadOnly="True" />
                <asp:BoundField DataField="TimeSheetTitle" HeaderText="Time Sheet Title" SortExpression="[TimeSheetTitle]"  />
                <asp:BoundField DataField="StartDate" DataFormatString="{0:d}" HtmlEncode="False" HeaderText="Start Date" SortExpression="[StartDate]"  />
                <asp:BoundField DataField="EndDate" DataFormatString="{0:d}" HtmlEncode="False" HeaderText="End Date" SortExpression="[EndDate]"  />
                <asp:BoundField DataField="DateOfCreation" DataFormatString="{0:d}" HtmlEncode="False" HeaderText="Date Of Creation" SortExpression="[DateOfCreation]"  />
                <data:BoundRadioButtonField DataField="Locked" HeaderText="Locked" SortExpression="[Locked]"  />
                <asp:BoundField DataField="ReviewedBy" HeaderText="Reviewed By" SortExpression="[ReviewedBy]"  />
                <data:HyperLinkField HeaderText="Employee Id" DataNavigateUrlFormatString="EmployeesEdit.aspx?EmployeeId={0}" DataNavigateUrlFields="EmployeeId" DataContainer="EmployeeIdSource" DataTextField="LastName" />

            </Columns>
            <EmptyDataTemplate>
                <b>No TimeSheets Found!</b>
            </EmptyDataTemplate>
        </data:EntityGridView>
        <asp:GridView ID="GridView2" runat="server">
    </asp:GridView>
        <br />
        <asp:Button runat="server" ID="btnTimeSheets" OnClientClick="javascript:location.href='TimeSheetsEdit.aspx'; return false;" Text="Add New"></asp:Button>
        <data:TimeSheetsDataSource ID="TimeSheetsDataSource" runat="server"
            SelectMethod="GetPaged"
            EnablePaging="True"
            EnableSorting="True"
            EnableDeepLoad="True"
            >
            <DeepLoadProperties Method="IncludeChildren" Recursive="False">
                <Types>
                    <data:TimeSheetsProperty Name="Employees"/> 
                    <%--<data:TimeSheetsProperty Name="TimeSheetDetailsCollection" />--%>
                </Types>
            </DeepLoadProperties>
            <Parameters>
                <data:CustomParameter Name="WhereClause" Value="" ConvertEmptyStringToNull="false" />
                <data:CustomParameter Name="OrderByClause" Value="" ConvertEmptyStringToNull="false" />
                <asp:ControlParameter Name="PageIndex" ControlID="GridView1" PropertyName="PageIndex" Type="Int32" />
                <asp:ControlParameter Name="PageSize" ControlID="GridView1" PropertyName="PageSize" Type="Int32" />
                <data:CustomParameter Name="RecordCount" Value="0" Type="Int32" />
            </Parameters>
        </data:TimeSheetsDataSource>

</asp:Content>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

青衫负雪 2024-08-25 00:22:32

问题可能是 GridView1 不会自动添加到 Designer.cs 文件中。如果是这种情况,请手动将其添加到设计器中。

Problem can be that GridView1 is not automatically added in designer.cs file. If that is case add it in designer manually.

少女情怀诗 2024-08-25 00:22:32

假设一个网站项目验证在构建它时您没有收到如下警告:

生成设计器文件失败:[失败原因]

您似乎没有注册自定义控件EntityGridView.请参阅注册指令了解如何执行此操作。

Assuming a WebSite project verify that when building it you do not get Warnings like:

Generation of designer file failed: [Failure Reason]

It seems that you're not registering the custom control EntityGridView. See the Register directive to see how you can do it.

二手情话 2024-08-25 00:22:32

当我将现有文件(.aspx + .aspx.cs)“添加”到项目中并且设计器文件尚未自行更新时,我曾经遇到过此问题。我已经尝试了这里写的许多/所有内容,但我发现创建一个新文件,复制代码前面的代码,然后复制代码后面的代码,然后重建基本上可以解决问题。是的,这很痛苦*,具体取决于您正在使用的文件的大小,但这通常发生在我想快速测试我遇到的一些演示代码时(一些新项目等)并将其放入我本地的VS中。

I've had this problem before when I've 'added' an existing file (.aspx + .aspx.cs) to a project and the designer file hasn't updated itself. I've tried many/all of the things written here, but I find that creating a new file, copying the code-front code in, then the code-behind and then rebuilding essentially does the trick. Yes, it's a pain in the * depending on the size of the file(s) you're working with, but this typically happens when I want to quickly test some demo code I've come across (some new project etc.) and throw it into my local VS.

残龙傲雪 2024-08-25 00:22:32

它是嵌套的,所以有些事情不会自动发生。

  1. 您可能必须手动将其添加到设计器中,或者(在 VB 中)显式使用 handles 关键字或(在 C# 中)显式连接“+=”运算符。
  2. 确保所有事件或在控件标记中明确说明

由于我看到您明确列出了事件,所以我会检查设计器。

It is nested, so some things don't happen automatically.

  1. You might have to manually add it to the designer, or else (in VB) explicitly use the handles keyword or (in C#) explicitly wire up with "+=" operator.
  2. Make sure all events or explicitly stated in the control mark-up

Since I see you list the event explicitly, I'd check the designer.

爱要勇敢去追 2024-08-25 00:22:32

我在 Visual Studio 2010 中遇到了同样的问题。design.cs 文件已正确生成。我关闭了 Visual Studio,然后重新打开它。这为我解决了这个问题(经过多次挫折)。

I had this same problem in Visual Studio 2010. The design.cs file was correctly generated. I closed Visual Studio, and reopened it. This resolved this issue for me (after much frustration).

旧时光的容颜 2024-08-25 00:22:32

我不知道这是否有帮助,但我一直在与类似的情况作斗争。

情况:我已将修改后的一些模板化 ASP.NET Web 项目中的一些代码包含到我的项目中 - 特别是登录标记。由于某种原因,“UserName”文本框控件之一拒绝在设计器中被识别。奇怪的是,下一行标记上的“UserNameLabel”控件被识别:

<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="Logon.aspx.cs" MasterPageFile="~/Site.master" Inherits="SimpleWebApp.Logon" %>

<asp:Content ID="LogonRegister" ContentPlaceHolderID="MainContent" runat="server">
     <div></div>
        <table align="center">
        <tr>
            <td valign="top">
                 *<asp:TextBox ID="TextBox1" runat="server" CssClass="textEntry"></asp:TextBox>*
                 <asp:Login ID="LoginUser" runat="server" EnableViewState="true" RenderOuterTable="false">
                    <LayoutTemplate>
                        <span class="failureNotification">
                            <asp:Literal ID="FailureText" runat="server"></asp:Literal>
                        </span>
                        <asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification"/>
                        <div class="accountInfo">
                            <fieldset class="login">
                                <legend>Log In</legend>
                                <p>
                                    **<asp:Label ID="lblUserNameLabel" runat="server">Username:</asp:Label>**
                                    ***<asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>***
                                </p>
...

我尝试过的:
我重新启动了 VWD 2010,
删除了设计器文件并通过将页面转换为 Web 应用程序来重新创建它
更改了文本框的名称,
删除并重新创建文本框。

我决定进行一些实验,发现在 asp:Login 标记外部添加一个典型的文本框可以被识别,而在该标记内部添加它则使其在设计器中无法识别。

我认为这可能会帮助我自己或其他人拼凑出可能发生的事情。

任何人都知道什么可能会导致 asp:Login 标记周围出现这种行为?

I don't know if this will help, but I've been fighting with a similar situation.

The situation: I have included some code from the modified some of the templated asp.net web project into my project - specifically the login markup. For some reason, one of the "UserName" Textbox control refuses to be recognized in the designer. Strangely enough, the "UserNameLabel" control on the next line of markup is recognized:

<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="Logon.aspx.cs" MasterPageFile="~/Site.master" Inherits="SimpleWebApp.Logon" %>

<asp:Content ID="LogonRegister" ContentPlaceHolderID="MainContent" runat="server">
     <div></div>
        <table align="center">
        <tr>
            <td valign="top">
                 *<asp:TextBox ID="TextBox1" runat="server" CssClass="textEntry"></asp:TextBox>*
                 <asp:Login ID="LoginUser" runat="server" EnableViewState="true" RenderOuterTable="false">
                    <LayoutTemplate>
                        <span class="failureNotification">
                            <asp:Literal ID="FailureText" runat="server"></asp:Literal>
                        </span>
                        <asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification"/>
                        <div class="accountInfo">
                            <fieldset class="login">
                                <legend>Log In</legend>
                                <p>
                                    **<asp:Label ID="lblUserNameLabel" runat="server">Username:</asp:Label>**
                                    ***<asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>***
                                </p>
...

What I've tried:
I've restarted VWD 2010,
deleted the designer file and recreated it through converting the page to a web application
changed the name of the Textbox,
deleted and recreated the Textbox.

I decided to experiment a little, and discovered that adding a typical textbox just outside the asp:Login tag is recognized, while adding it just inside that tag leaves it unrecognized in the designer.

Figured this might help myself or someone else to piece together what might be going on.

Anyone have any idea what might cause this behavior around the asp:Login tag?

终弃我 2024-08-25 00:22:32

有关密切相关的答案,请访问稍微类似的问题,如何强制 Visual Studio 为 aspx/ascx 文件重新生成 .designer 文件?

@sameer:我很想知道您在转换之前是否尝试将 CodeFile="TimeSheets.aspx.cs" 替换为 CodeBehind="TimeSheets.aspx.cs"该项目。

For closely related answers, visit a slightly similar question, How do you force Visual Studio to regenerate the .designer files for aspx/ascx files?.

@sameer: I'd be interested to hear if you tried to replace CodeFile="TimeSheets.aspx.cs" with CodeBehind="TimeSheets.aspx.cs" before converting the project.

究竟谁懂我的在乎 2024-08-25 00:22:32

我知道这是一个旧线程,但我只是在解决与此类似的问题。几天后,我发现我的项目中有问题页面和代码的备份副本。在编译时放置在新页面上的对象上,我不断收到错误“当前上下文中不存在”,即使智能感知识别了它们。我猜 VS 会因为默认命名空间中的重复页面而感到困惑。一旦我删除了备份,我就神奇地不再出现错误了。

I know this is an old thread, but I just struggled with an issue similar to this. After a couple of days, I figured out that I had a backup copy of the problem page and code behind in my project. I kept getting the error "does not exist in the current context" at compile time on objects placed on the new page, even though intellisense recognized them. I guess VS was getting confused because of the duplicate pages in the default namespace. Once I got rid of the backup, I magically stopped getting the errors.

岛歌少女 2024-08-25 00:22:32

我遇到了同样的问题,没有一个解决方案对我有用。我没有浪费太多时间就发现,管理部分中的许多 ASPX 页面都被赋予了与项目实体文件中的实体相同的类名。此外,每个页面都列出了导致冲突的实体命名空间,因为在 using 指令中添加实体命名空间后,存在命名空间冲突。我仔细检查并将“Page”添加到每个 ASPX 页面中,重新编译,一切正常。

我知道这个帖子已经得到了回答,但我想包含这个描述,以防其他人也有同样的问题,并且上述解决方案都不起作用,给他们一些可能是问题的东西。

我的项目中有 21 个页面需要更改,这里是一个使用 UserEntity 和 Admin/UserEntity.aspx 的示例:

UsersEntity.aspx 前端 aspx 页面中,更改

<%@ Page Language="C#"
         Theme="Default" 
         MasterPageFile="~/MasterPages/admin.master" 
         AutoEventWireup="true" 
         Inherits="UsersEntity" 
         Title="UsersEntity" 
         Codebehind="UsersEntity.aspx.cs" 
%>

为:

<%@ Page Language="C#"
         Theme="Default" 
         MasterPageFile="~/MasterPages/admin.master" 
         AutoEventWireup="true" 
         Inherits="UsersEntityPage" 
         Title="UsersEntity" 
         Codebehind="UsersEntity.aspx.cs" 
%>

在 UsersEntity.aspx 中.cs 代码后面,我将: 更改

public partial class UsersEntity : System.Web.UI.Page

为:

public partial class UsersEntityEntityPage : System.Web.UI.Page

并在 UsersEntity.aspx.designer.cs (设计器页面)中:
当我将页面后面的代码更改为:

public partial class UsersEntityPage {

我对其他每个有问题的页面(除了“编辑”页面之外的所有页面)都执行了此操作

时,该页面会自动更改。 -- 我想我可以删除实体名称空间的 using 指令,但我真的希望能够在我的页面中访问它,而且我认为页面类具有完全相同的名称是不好的作为我的实体类。这样的情况让我感到困惑。

I had the same problem, none of the solutions worked for me. I figured out without wasting too much time, that many of the ASPX pages in the Admin section were being given the same class name as the entities in the project entity files. Also, each of the pages listed the Entities namespace causing conflicts since after adding the entity namespace in the using directives, there were namespace conflicts. I went through and added "Page" to each of the ASPX page, recompiled and everything worked fine.

I know this thread has already been answered, but I wanted to include this description in case there are others that have this same problem and none of the above solutions worked, to give them something else that might be the issue.

I had 21 pages to change in my project, here is an example using the UserEntity and the Admin/UserEntity.aspx:

in UsersEntity.aspx front side aspx page, changed:

<%@ Page Language="C#"
         Theme="Default" 
         MasterPageFile="~/MasterPages/admin.master" 
         AutoEventWireup="true" 
         Inherits="UsersEntity" 
         Title="UsersEntity" 
         Codebehind="UsersEntity.aspx.cs" 
%>

to:

<%@ Page Language="C#"
         Theme="Default" 
         MasterPageFile="~/MasterPages/admin.master" 
         AutoEventWireup="true" 
         Inherits="UsersEntityPage" 
         Title="UsersEntity" 
         Codebehind="UsersEntity.aspx.cs" 
%>

in the UsersEntity.aspx.cs code behind, I changed:

public partial class UsersEntity : System.Web.UI.Page

to:

public partial class UsersEntityEntityPage : System.Web.UI.Page

and in the UsersEntity.aspx.designer.cs (Designer Page):
That page got automatically changed when I changed the code behind page to:

public partial class UsersEntityPage {

I did that for each of the other offending pages, which were all of them except for the "Edit" pages.

-- I guess I could have just removed the using directive to the Entity name space, but I really want to be able to have access to that in my pages, plus I think it is ungood for the page classes to have the exact same name as my entity classes. It causes confusion to me to have it like that.

勿忘初心 2024-08-25 00:22:32

复制 _.aspx 文件代码并将其粘贴到 _.aspx.cs 页面上。

如果不是,则从顶部导入命名空间。

  1. <%@ 页面语言="C#" AutoEventWireup="true" %> <%@导入
    命名空间=“System.Data”%> <%@导入
    命名空间=“System.Data.SqlClient”%>

copy the _.aspx file code and paste it on the _.aspx.cs page.

if it is not then import namespaces all the way top.

  1. <%@ Page Language="C#" AutoEventWireup="true" %> <%@ Import
    Namespace="System.Data" %> <%@ Import
    Namespace="System.Data.SqlClient" %>
霓裳挽歌倾城醉 2024-08-25 00:22:32

我发现designer.cs文件中存在不正确的文件引用名称。这是代码文件名,末尾添加了 1。我删除了 1,代码运行没有错误。在此之前,我删除并重建了设计器文件,但没有解决。

I found that there was an incorrect file reference name in the designer.cs file. It was the code filename with a 1 added to the end. I removed the 1 and the code ran without error. Prior to this I deleted and rebuilt the designer file without resolution.

菊凝晚露 2024-08-25 00:22:32

最简单的方法是:

  1. 删除设计器文件 (YourFilename.aspx.designer.cs)
  2. 在解决方案资源管理器中选择 ASPX 文件,
  3. 在“项目”菜单下查找“转换为 Web 应用程序”项并单击它。在对话框窗口中单击“是”。
  4. 打开新创建的设计器文件,并确保命名空间与主 aspx.cs 文件上的命名空间匹配(非常重要)
  5. 关闭设计器文件。
  6. 保存解决方案。关闭它然后重新打开。

The easiest way is to:

  1. Delete the designer file (YourFilename.aspx.designer.cs)
  2. Select the ASPX file in Solution Explorer
  3. Under Projects menu look for the item "Convert to Web Application" and click on it. Click Yes on the dialog window.
  4. Open up the newly created designer file and make sure the namespace matches the namespace on the primary aspx.cs file (VERY IMPORTANT)
  5. Close the designer file.
  6. Save the solution. Close it and then reopen.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文