tags:

views:

46

answers:

4

I've had the same problem a couple of times with different ASPX pages after renaming them and I am surprised that I can't find someone else with the same problem on stackoverflow.

When I run my ASP.NET C# project, the debugger gives me a message like this one.

Error   5   The name 'txtTitle' does not exist in the current context

It seems that the aspx and aspx.cs files at no longer bound. The only fix I have found for this is to recreate the page and copy/paste my code.

Any idea how to fix this without recreating the whole thing?

Thanks

A: 

I am surprised at this occurring I regularly rename Silverlight user controls with no harmful side-effects.

Are all of the references to classes being renamed in the aspx page and code behind ?

You might try using this util to relink them.

Adrian Russell
A: 

I've had the same problem and noticed that sometimes, but not always, the CodeFile setting in the .aspx page is not updated when the class is changed. If this is the same problem you have, you can change it manually:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyClass.aspx.cs" Inherits="MyClass" %>
                                                        ^^^^^^^
Sam
A: 

Some times I see these errors on my error list. But If I actually open that file, the error would go away. Do anyone else experience this? Is there a way to over come that? (ie prevent it from showing on error list)

franklins
+3  A: 

The code file contains a partial class that is referenced in the ASPX header declaration. Both file name and the actual class in the ASPX header have to match for this to work.

<%@ Page Title="TestPage" Language="C#"  AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="TestPage" %>

In your case probably the class name does not match. Check if the class name in the codebehind .cs file matches the name after Inherits.

The concept of partial classes used in ASP.NET is detailed here.

BrokenGlass
Just found out that I was missing the namespace of my page's class in the inherit attribute. I'll be sure to look at this the next time it happens to me. Thank you!
Jason