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

Discussion in 'ASP .Net' started by Josh Mitts, Nov 2, 2005.

  1. Josh Mitts

    Josh Mitts Guest

    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" %>

    --

    Joshua Mitts



    "ABC" <> wrote in message
    news:...
    > How to create a web page class for inhert web page using ASP.NET 1.1 and
    > 2.0?
    >
    >
    Josh Mitts, Nov 2, 2005
    #1
    1. Advertising

  2. Josh Mitts

    Mr Newbie Guest


    > <%@ 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.




    "Josh Mitts" <> wrote in message
    news:...
    > 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" %>
    >
    > --
    >
    > Joshua Mitts
    >
    >
    >
    > "ABC" <> wrote in message
    > news:...
    >> How to create a web page class for inhert web page using ASP.NET 1.1 and
    >> 2.0?
    >>
    >>

    >
    >
    Mr Newbie, Nov 2, 2005
    #2
    1. Advertising

  3. 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"




    Juan T. Llibre, ASP.NET MVP
    ASP.NET FAQ : http://asp.net.do/faq/
    Foros de ASP.NET en EspaƱol : http://asp.net.do/foros/
    ======================================
    "Josh Mitts" <> wrote in message
    news:...
    > 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" %>
    >
    > Joshua Mitts
    >



    > "ABC" <> wrote in message news:...
    >> How to create a web page class for inhert web page using ASP.NET 1.1 and 2.0?
    Juan T. Llibre, Nov 2, 2005
    #3
  4. Josh Mitts

    ABC Guest

    How to create a web page class for inhert web page using ASP.NET 1.1 and
    2.0?
    ABC, Nov 2, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick
    Replies:
    2
    Views:
    641
    Steven Cheng[MSFT]
    Oct 1, 2004
  2. E11
    Replies:
    1
    Views:
    4,716
    Thomas Weidenfeller
    Oct 12, 2005
  3. jd
    Replies:
    3
    Views:
    340
  4. shapper
    Replies:
    1
    Views:
    730
    Chris Fulstow
    Oct 10, 2006
  5. chandan
    Replies:
    2
    Views:
    3,305
    bruce barker
    Dec 3, 2007
Loading...

Share This Page