Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Broken link between aspx and aspx.cs files

Tags:

c#

asp.net

vb.net

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

like image 257
Jason Avatar asked Jan 30 '26 06:01

Jason


1 Answers

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.

like image 170
BrokenGlass Avatar answered Jan 31 '26 21:01

BrokenGlass