How to create a web page class for inhert web page using ASP.NET 1.1 and 2.0?

J

Josh Mitts

Hi,

Do you mean a class in a code-behind file? The method is slightly different
in ASP.NET 2.0 than in 1.1. If you are using ASP.NET 1.1, you need to
compile your code-behind file into a class, place the compiled .dll in the
bin directory, and have your page inherit from that class using the
following syntax:

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

(note the CodeBehind setting is optional, and merely gives the compiler a
location for your source, helps out visual designers, etc.).

However, a tool like Visual Studio will set up this two-file system,
compilation, page directive, etc. automatically for you.

On the other hand, if you are using ASP.NET 2.0, you only need to place the
..cs file alongside the .aspx file and use the following syntax -- ASP.NET
will compile it automatically:

<%@ Page Language="C#" CodeFile="MyPage.aspx.cs" Inherits="MyPage" %>
 
M

Mr Newbie

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

(note the CodeBehind setting is optional, and merely gives the compiler a
location for your source, helps out visual designers, etc.).

I havent tried this recently, but Im sure a while back I tried to locate the
code in another location other than the root by altering this CodeBehind
location attribute and found you could not seperate the aspx from .cs in
terms of location.

Can you validate this please ?


Cheers - Mr N.
 
J

Juan T. Llibre

The second part is fine.

Regarding the first part, if you've already compiled
and placed your dll in the bin directory, what you need
to do is import the namespace to the aspx file:

<%@ Import Namespace="YourDLLsNamespace" %>

ASP.NET 1.1 will also automatically compile any code-behind file
it finds in the same directory as an aspx file, if it has the directive you mention :

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

AND if the file naming follows this scheme : MyPage.aspx and MyPage.aspx.cs

It's worthwhile mentioning that in 1.1, the default wireup was
AutoEventWireup="false" , while in 2.0, it's AutoEventWireup="true"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top