Paul Michaels
Paul Michaels

Reputation: 16695

.aspx codefile page unable to recognise control on the page

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?

Upvotes: 0

Views: 1374

Answers (2)

besamelsosu
besamelsosu

Reputation: 481

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.

Upvotes: 2

Mantorok
Mantorok

Reputation: 5266

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

Upvotes: 0

Related Questions