tags:

views:

56

answers:

3

I have a ASP.NET web page developed in VS 2008 with the below Page directive in the aspx page

<%@ Page Language="C#" CodeBehind="SupplierAnalysisReport.aspx.cs" %>

I placed a asp.net button control in my page and double clicked on it to write an event.It is showing the event (method) in the aspx page itself. Why it is not getting added to the aspx.cs file ?

I have removed the Inherits attribute from the page since i want to deploy this to an environment with aspx files and aspx.cs file. (NOT DLL'S)

A: 

It is because if you remove the Inherits attribute the designer is no longer capable of finding the partial class defined in your code behind. CodeBehind and Inherits attributes work together.

CodeBehind:

Specifies the name of the compiled file that contains the class associated with the page. This attribute is not used at run time.

This attribute is included for compatibility with previous versions of ASP.NET, to implement the code-behind feature. In ASP.NET version 2.0, you should instead use the CodeFile attribute to specify the name of the source file, along with the Inherits attribute to specify the fully qualified name of the class.

Darin Dimitrov
A: 

Try this (replacing namespace.to.my.class with the namespace containing the SupplierAnalysis class definition):

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SupplierAnalysisReport.aspx.cs" Inherits="namespace.to.my.class.SupplierAnalysisReport" %>

You need the Inherits atttibue as well as CodeBehind.

rob
+1  A: 

You might try using CodeFile instead of CodeBehind in your Page directive. However, in that case you will also need to declare references to the controls on your page.

If you don't want to deploy a DLL, the usual solution is to structure your site as a Visual Studio "web site" instead of a "web application." With a web site, you can just copy all of your code and .aspx files to the server, where they will be compiled on first access.

RickNZ