how to use cs files?

Discussion in 'ASP .Net' started by Dan, Mar 6, 2005.

  1. Dan

    Dan Guest

    I know this is tupid but coming from a c++ background to asp.net in c# has
    been a real awakening.

    I have made my class and placed it in a .cs file but i do not know how i am
    supposed to get my aspx pages to use that class when they run?

    Could someone please help me in explaining how i programatically include a
    cs file thanks.
     
    Dan, Mar 6, 2005
    #1
    1. Advertising

  2. Dan,

    CS files by themselves do not do much -- you can include them in an web
    project, or a class library, and start using the classes they contain. So,
    if you have a class within a CS file, it becomes a part of the library it is
    in (either the web project, or a separate library).

    --
    Manohar Kamath
    Editor, .netWire
    www.dotnetwire.com


    "Dan" <> wrote in message
    news:%...
    > I know this is tupid but coming from a c++ background to asp.net in c# has
    > been a real awakening.
    >
    > I have made my class and placed it in a .cs file but i do not know how i

    am
    > supposed to get my aspx pages to use that class when they run?
    >
    > Could someone please help me in explaining how i programatically include a
    > cs file thanks.
    >
    >
     
    Manohar Kamath, Mar 6, 2005
    #2
    1. Advertising

  3. Dan

    Scott M. Guest

    The .cs files are just containers for source code (modules). The code in
    those files gets compiled into the project's assembly (.dll) which is
    deployed, along with the .aspx files) to a web server.

    In the .aspx files, there is a Page directive that includes an "Inherits"
    clause. When a client requests a particular .aspx page, that page then
    calls into the assembly and makes an instance of the class mentioned in the
    ..aspx file. From there, the page object can fire and respond to events and
    run its compiled code.

    You do not need/want to deploy the .cs files to the production web server as
    these source code files get compiled into the final assembly.


    "Dan" <> wrote in message
    news:%...
    >I know this is tupid but coming from a c++ background to asp.net in c# has
    >been a real awakening.
    >
    > I have made my class and placed it in a .cs file but i do not know how i
    > am supposed to get my aspx pages to use that class when they run?
    >
    > Could someone please help me in explaining how i programatically include a
    > cs file thanks.
    >
     
    Scott M., Mar 6, 2005
    #3
  4. Hi Dan,

    You need to compile the class file into a class library. Which is called an
    assembly ( .dll ). In you visual studio make a reference to it. Also in your
    code behind import it ( In C# using directive).

    Create an object for the class in your code behin and you can access the
    methods...

    HTH,

    Need any help, do post a msg back..

    Happy Coding


    "Dan" wrote:

    > I know this is tupid but coming from a c++ background to asp.net in c# has
    > been a real awakening.
    >
    > I have made my class and placed it in a .cs file but i do not know how i am
    > supposed to get my aspx pages to use that class when they run?
    >
    > Could someone please help me in explaining how i programatically include a
    > cs file thanks.
    >
    >
    >
     
    =?Utf-8?B?VmlzaG51LUNoaXZ1a3VsYQ==?=, Mar 6, 2005
    #4
  5. re:
    > I have made my class and placed it in a .cs file but i do not know how i
    > am supposed to get my aspx pages to use that class when they run?


    You'd compile the .cs file with a command-line like :

    csc /t:library /out:..\bin\YourClass.dll YourClass.cs /r:system.dll
    /r:system.data.dll /r:system.xml.dll

    And call it in your .aspx pages with a

    <%@ Import Namespace="YourClassName" %>

    Now, you can reference your methods with :

    YourClassName.YourMethod





    Juan T. Llibre
    ASP.NET MVP
    http://asp.net.do/foros/
    Foros de ASP.NET en Español
    Ven, y hablemos de ASP.NET...
    ======================

    "Dan" <> wrote in message
    news:%...
    >I know this is tupid but coming from a c++ background to asp.net in c# has
    >been a real awakening.
    >
    > I have made my class and placed it in a .cs file but i do not know how i
    > am supposed to get my aspx pages to use that class when they run?
    >
    > Could someone please help me in explaining how i programatically include a
    > cs file thanks.
    >
     
    Juan T. Llibre, Mar 6, 2005
    #5
  6. Dan

    gaidar Guest

    Ypu can use Src attribute in @ Page directive, then toy .cs file will
    compile on the fly then user requests a page.

    <% @ Page Src="MyCSClass.cs" %>


    --
    Gaidar Magdanurov
    VBStreets, Editor-in-Chief
    mailto: / http://www.vbstreets.org

    "Dan" <> wrote in message
    news:%...
    >I know this is tupid but coming from a c++ background to asp.net in c# has
    >been a real awakening.
    >
    > I have made my class and placed it in a .cs file but i do not know how i
    > am supposed to get my aspx pages to use that class when they run?
    >
    > Could someone please help me in explaining how i programatically include a
    > cs file thanks.
    >
     
    gaidar, Mar 6, 2005
    #6
  7. As an additional note, you may want to configure the IIS to create the web
    application for the subweb. (I believe using the root application is okay,
    but I think it would be somehow more secure to create seperate application
    if the page is located in a subweb, especially if you choose to prevent
    upper level path access)

    A web.config file may also be needed. (Not quite sure about this one.)

    "Scott M." <> ¦b¶l¥ó
    news: ¤¤¼¶¼g...
    > The .cs files are just containers for source code (modules). The code in
    > those files gets compiled into the project's assembly (.dll) which is
    > deployed, along with the .aspx files) to a web server.
    >
    > In the .aspx files, there is a Page directive that includes an "Inherits"
    > clause. When a client requests a particular .aspx page, that page then
    > calls into the assembly and makes an instance of the class mentioned in

    the
    > .aspx file. From there, the page object can fire and respond to events

    and
    > run its compiled code.
    >
    > You do not need/want to deploy the .cs files to the production web server

    as
    > these source code files get compiled into the final assembly.
    >
    >
    > "Dan" <> wrote in message
    > news:%...
    > >I know this is tupid but coming from a c++ background to asp.net in c#

    has
    > >been a real awakening.
    > >
    > > I have made my class and placed it in a .cs file but i do not know how i
    > > am supposed to get my aspx pages to use that class when they run?
    > >
    > > Could someone please help me in explaining how i programatically include

    a
    > > cs file thanks.
    > >

    >
    >
     
    Lau Lei Cheong, Mar 7, 2005
    #7
  8. Talking about csc.exe, is there anyway to compile the whole site (including
    the subdirs) into single DLL, just like what the VS.NET IDE would do, using
    CSC without a makefile?

    Just for curiosity...

    "Juan T. Llibre" <> ¦b¶l¥ó
    news:% ¤¤¼¶¼g...
    > re:
    > > I have made my class and placed it in a .cs file but i do not know how i
    > > am supposed to get my aspx pages to use that class when they run?

    >
    > You'd compile the .cs file with a command-line like :
    >
    > csc /t:library /out:..\bin\YourClass.dll YourClass.cs /r:system.dll
    > /r:system.data.dll /r:system.xml.dll
    >
    > And call it in your .aspx pages with a
    >
    > <%@ Import Namespace="YourClassName" %>
    >
    > Now, you can reference your methods with :
    >
    > YourClassName.YourMethod
    >
    >
    >
    >
    >
    > Juan T. Llibre
    > ASP.NET MVP
    > http://asp.net.do/foros/
    > Foros de ASP.NET en Español
    > Ven, y hablemos de ASP.NET...
    > ======================
    >
    > "Dan" <> wrote in message
    > news:%...
    > >I know this is tupid but coming from a c++ background to asp.net in c#

    has
    > >been a real awakening.
    > >
    > > I have made my class and placed it in a .cs file but i do not know how i
    > > am supposed to get my aspx pages to use that class when they run?
    > >
    > > Could someone please help me in explaining how i programatically include

    a
    > > cs file thanks.
    > >

    >
    >
     
    Lau Lei Cheong, Mar 7, 2005
    #8
  9. Not with csc.exe, though, and you'll
    need ASP.NET 2.0 to do it.

    There's 2 ways to do that in ASP.NET 2.0 :

    Pre-compiling a site in place and
    pre-compiling a site for deployment.

    See :
    http://msdn.microsoft.com/asp.net/whidbey/aspnetwhidbey.aspx
    ( Scroll down to "Pre-Compilation of Applications" )

    and
    http://pluralsight.com/blogs/fritz/archive/2004/11/11/3415.aspx



    Juan T. Llibre
    ASP.NET MVP
    http://asp.net.do/foros/
    Foros de ASP.NET en Español
    Ven, y hablemos de ASP.NET...
    ======================

    "Lau Lei Cheong" <> wrote in message
    news:...
    > Talking about csc.exe, is there anyway to compile the whole site
    > (including
    > the subdirs) into single DLL, just like what the VS.NET IDE would do,
    > using
    > CSC without a makefile?
    >
    > Just for curiosity...
    >
    > "Juan T. Llibre" <> ¦b¶l¥ó
    > news:% ¤¤¼¶¼g...
    >> re:
    >> > I have made my class and placed it in a .cs file but i do not know how
    >> > i
    >> > am supposed to get my aspx pages to use that class when they run?

    >>
    >> You'd compile the .cs file with a command-line like :
    >>
    >> csc /t:library /out:..\bin\YourClass.dll YourClass.cs /r:system.dll
    >> /r:system.data.dll /r:system.xml.dll
    >>
    >> And call it in your .aspx pages with a
    >>
    >> <%@ Import Namespace="YourClassName" %>
    >>
    >> Now, you can reference your methods with :
    >>
    >> YourClassName.YourMethod
    >>
    >>
    >>
    >>
    >>
    >> Juan T. Llibre
    >> ASP.NET MVP
    >> http://asp.net.do/foros/
    >> Foros de ASP.NET en Español
    >> Ven, y hablemos de ASP.NET...
    >> ======================
    >>
    >> "Dan" <> wrote in message
    >> news:%...
    >> >I know this is tupid but coming from a c++ background to asp.net in c#

    > has
    >> >been a real awakening.
    >> >
    >> > I have made my class and placed it in a .cs file but i do not know how
    >> > i
    >> > am supposed to get my aspx pages to use that class when they run?
    >> >
    >> > Could someone please help me in explaining how i programatically
    >> > include

    > a
    >> > cs file thanks.
    >> >

    >>
    >>

    >
    >
     
    Juan T. Llibre, Mar 7, 2005
    #9
    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. Tom Hansen
    Replies:
    2
    Views:
    2,466
    Tom Hansen
    Nov 21, 2003
  2. Andy Fish
    Replies:
    0
    Views:
    305
    Andy Fish
    Jun 23, 2004
  3. crazyprakash
    Replies:
    4
    Views:
    3,433
    adrian
    Oct 30, 2005
  4. Replies:
    4
    Views:
    999
    M.E.Farmer
    Feb 13, 2005
  5. Replies:
    3
    Views:
    1,536
    Rolf Magnus
    Jan 18, 2009
Loading...

Share This Page