3
votes

For whatever reason my .aspx will only recognize the code behind when the Page directive is using CodeFile and not CodeBehind. Also, it gives a parser error on runtime. But I need CodeBehind to publish the site.

  • Every other page in the web application uses CodeBehind.
  • I've tried deleting and recreating the file, even leaving it empty, still an error.
  • I've tried deleting the designer file and converting the .aspx to a web application.
  • The page directive references (namespace, class) are correct.
  • Tried deleting the obj.
  • Tried cleaning and rebuilding.

I'm out options here. Everything I've googled so far hasn't panned out. Why can't CodeBehind be used?!

.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/App/Masters/Default.Master" AutoEventWireup="true" CodeBehind="BlogPost.aspx.cs" Inherits="WebApplication.App.Templates.BlogPost" %>

.aspx.cs

namespace WebApplication.App.Templates
{
    public partial class BlogPost : BaseTemplate
    {
1
stackoverflow.com/questions/73022/codefile-vs-codebehind - maybe you're using the wrong attribute? - Tim
@Tim CodeFile works, but won't work when published. Also, every other page works with CodeBehind fine. It's just this one all of a sudden. - Ber53rker
I want to say I saw this before - it's one specific page, right? I think when it happened to me I did a clean/rebuild and it worked. Something else you might want to try is deleting the IIS Temporary Internet Files. You've got to stop IIS and manually drill down to the directory. (I used to see this a lot when I was doing work with the Ektron CMS) - Tim

1 Answers

4
votes

Maybe your .csproj file was corrupted somehow?

Check to see that the entry for your file(s) look like this in your project file:

<Compile Include="BlogPost.aspx.cs">
  <DependentUpon>BlogPost.aspx</DependentUpon>
  <SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="BlogPost.aspx.designer.cs">
  <DependentUpon>BlogPost.aspx</DependentUpon>
</Compile>