Home » Programming / Coding

does not contain a definition for context error in ASP .Net

3 February 2009 7,520 views No Comment

I created a masterpage that uses another masterpage. I copied the first line that defines the code files, master page used etc. Then I got into this error on compilation:

does not contain a definition for context error

Also the page using the masterpage was throwing error.

I never seen an error like this before. After digging online and looking at the code realized I didn’t do something right.

<%@ Master Language=”C#” AutoEventWireup=”true” MasterPageFile=”~/MasterPageGeneric.master” CodeFile=”MasterPageManager.master.cs” Inherits=”MasterPageManager” %>

Since the new master page was inside a folder, and the parent masterpage was in root level, copying the first line was my source of error. I forgot to update the Inherts part accordingly. By default ASP .Net uses foldername_filename as the name of the class; and the Inherts attribute should be updated accordingly.

<%@ Master Language=”C#” AutoEventWireup=”true” MasterPageFile=”~/MasterPageGeneric.master” CodeFile=”MasterPageManager.master.cs” Inherits=“manager_MasterPageManager” %>

Now that I have updated that part, errors went away.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.