简体   繁体   English

当前上下文中不存在控件 asp.net c#

[英]Control does not exist in current context asp.net c#

I have two files: FileGridCS.ascx and FileGridCS.ascx.cs我有两个文件:FileGridCS.ascx 和 FileGridCS.ascx.cs

Within FileGridCS.ascx: I have added the control:在 FileGridCS.ascx 中:我添加了控件:

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

The header of this file is:该文件的 header 为:

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

Now, my class FileGridCS.ascx.cs is not recognising 'gvFiles'.现在,我的 class FileGridCS.ascx.cs 无法识别“gvFiles”。 I Get the following error:我收到以下错误:

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

What am I doing wrong?, I am a little confused on why this happening when the control exists!我做错了什么?,当控件存在时为什么会发生这种情况,我有点困惑!

Thanks =)谢谢 =)

UPDATE更新

Just to let you know, my class FileGrid.ascx.cs is a public partial class*只是让你知道,我的 class FileGrid.ascx.cs 是一个公共部分类*

First You have to Specify the User Control on the.aspx Page首先,您必须在.aspx 页面上指定用户控件

In which src is Location of that User Control....其中 src 是该用户控件的位置....

In tagName with same name of.ascx in my case UserControl is GridControl.ascx and specify that tagName as GridControl在我的情况下,在具有相同名称 of.ascx 的 tagName 中,UserControl 是 GridControl.ascx 并将该 tagName 指定为 GridControl

And also use TagPrefix as your choice...并且还使用 TagPrefix 作为您的选择...

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

Then use as GridView Like Below Example...然后使用 GridView 就像下面的例子......

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM