开发者

.aspx codefile page unable to recognise control on the page

开发者 https://www.devze.com 2023-04-03 14:42 出处:网络
I am getting a compilation error on a website.There is a repeater declared in the aspx file as follows:

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.DataSour开发者_如何学Pythonce = 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?


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:

  • Ensure that your .cs file is set to Compile in the properties
  • Try using CodeBehind instead of CodeFile
  • If your page class is inside a namespace then ensure it is fully qualified in the aspx file
  • If you are using a Web Application Project then right-click and Convert to Web Application
0

精彩评论

暂无评论...
验证码 换一张
取 消