.aspx 代码文件页面无法识别页面上的控件
我在网站上收到编译错误。在 aspx 文件中有一个中继器声明如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyPage.aspx.cs"
Inherits="MyClass" %>
<asp:Repeater ID="rptMyRepeater" runat="server">
<ItemTemplate>
<tr>
<td>
…
类定义如下:
public partial class MyClass : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
rptMyRepeater.DataSource = GetMyDataSource();
rptMyRepeater.DataBind();
}
}
}
我遇到的问题是 rptMyRepeater 无法识别。请注意,我从另一个项目复制了这些文件,因此没有 Designer.cs 文件。
我遇到了 this 问题暗示“转换为 Web 应用程序”可以解决该问题。由于我引用的是 CodeFile 而不是 CodeBehind,这是否适用,或者是否有更好的方法?在这种情况下还需要设计师文件吗?
I am getting a compilation error on a website. There is a repeater declared in the aspx file as follows:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyPage.aspx.cs"
Inherits="MyClass" %>
<asp:Repeater ID="rptMyRepeater" runat="server">
<ItemTemplate>
<tr>
<td>
…
And the class is defined as follows:
public partial class MyClass : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
rptMyRepeater.DataSource = GetMyDataSource();
rptMyRepeater.DataBind();
}
}
}
The problem I have is that rptMyRepeater is not recognised. Note that I copied these files in from another project, and so don't have a designer.cs file.
I came across this question which implies a "Convert to Web Application" would fix the problem. As I'm referencing a CodeFile rather than a CodeBehind, does this apply, or is there a better way? Is a designer file even necessary in this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的意思是您不仅仅拥有 Designer.cs 的内容,请将其添加到 Designer.cs 中:
受保护的全局::System.Web.UI.WebControls.Repeater rptMyRepeater;
如果您根本没有 Designer.cs 文件,请将其添加到 aspx.cs -即代码文件 - 中,它应该可以工作。
简而言之,这相当于设计器文件应该做的事情,正如我所见,控件与类变量没有太大不同。
If what you are saying is you don't have just the contents of designer.cs, add this to designer.cs:
protected global::System.Web.UI.WebControls.Repeater rptMyRepeater;
If you do not have a designer.cs file at all, add it to aspx.cs -i.e codefile- and it should work.
Simply this is the equivalent of what the designer file supposed to be doing, controls are not much different than class variables as I see.
您可以检查以下几件事:
A couple of things you could check: