【问题标题】:Control does not exist in current context asp.net c#当前上下文asp.net c#中不存在控件
【发布时间】:2019-11-04 14:23:38
【问题描述】:

我有两个文件:FileGridCS.ascx 和 FileGridCS.ascx.cs

在 FileGridCS.ascx 中:我添加了控件:

<asp:GridView ID="gvFiles" runat="server"></asp:GridView>

这个文件的头是:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FileGridCS.ascx.cs"
    Inherits="UserControls_FileGridCS" %>

现在,我的类 FileGridCS.ascx.cs 无法识别“gvFiles”。我收到以下错误:

Severity Code   Description  Project          File  Line    Suppression State
Error    CS0103 The name 'gvFiles' does not         137     Active
                exist in the current context

我做错了什么?,当控件存在时为什么会发生这种情况,我有点困惑!

谢谢 =)

更新

只是让您知道,我的类 FileGrid.ascx.cs 是一个公共部分类*

【问题讨论】:

  • 没有足够的继续。请在具有public partial class ....cs 文件中包含完整的行。还可以尝试删除 gridview 并重新添加它(拖动它或在工具箱中单击它)。还包括所有引用gvFiles 或解释错误发生时间/地点的方法。

标签: c# asp.net gridview ascx


【解决方案1】:

首先您必须在 .aspx 页面上指定用户控件

其中 src 是该用户控件的位置....

在我的情况下,在与 .ascx 同名的 tagName 中,UserControl 是 GridControl.ascx,并将该 tagName 指定为 GridControl

还可以使用 TagPrefix 作为您的选择...

<%@ Register Src="~/App_UserControls/GridControl.ascx" TagName="GridControl" TagPrefix="UC" %>

然后像下面的示例一样用作 GridView...

<UC:GridControl ID="gvFiles" runat="server" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-06
    • 2014-12-09
    • 2011-07-09
    相关资源
    最近更新 更多