GreggO
GreggO

Reputation: 43

error running "working" web application in Visual Web Developer 2010 Express

I am picking up the support of an old .NET web application that was developed on Visual Studio 2008. However I am using Visual Web Developer 2010 Express. I've loaded the project code directly from the last working version as a web application. Everything compiles and loads setup to target .NET Framework version 3.5.

However when debugging, the first page requested results in a "Compilation error" with the message

"*CS1061: 'ASP.site_master' does not contain a definition for 'LinkButton2_Click' and no extension method 'LinkButton2_Click' accepting a first argument of type 'ASP.site_master' could be found (are you missing a using directive or an assembly reference?)*".

Here are the relevant code details:

From Site.Master:

  <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.Master.cs"  %>
   ...
   <asp:LoginView ID="LoginView1" runat="server" >
   <AnonymousTemplate>
      <asp:LinkButton ID="LinkButton2" runat="server" Click="LinkButton2_Click"> Login
      </asp:LinkButton>
   </AnonymousTemplate>

From Site.Master.cs:

 public partial class Site : BaseMasterPage  // BaseMasterPage is subclass of System.Web.UI.MasterPage
 ...
 public void LinkButton2_Click(object sender, EventArgs e)
    {
        Response.Redirect("/Login.aspx?ReturnURL="+ Request.Url.AbsolutePath);
    }

Clearly the code is defined and there are no apparent typos.

I'm primarily a Java developer but have fair experience with .NET. However this issue has me stumped so I need some help to navigate through it. I have researched it extensively via Google and this type of problem has been reported numerous times including here on Stack Overflow. But none of the resolutions given on previous reports has helped to resolve it for me. It is exceptionally puzzling because the code clearly works as it is currently running in production. It seems to be a version problem between Visual Studio 2008 and Visual Web Developer 2010 Express.

Upvotes: 4

Views: 183

Answers (1)

Brinky
Brinky

Reputation: 418

Add in an Inherits="Site" attribute to your Master declaration. This may allow it to hook up properly with the codebehind file.

Site.Master.aspx:

<%@ Master Language="C#" Inherits="<full namespace>.Site" CodeBehind="Site.Master.cs" AutoEventWireup="true" %>

where must be as in Site.Master.cs

Upvotes: 2

Related Questions