how to use cs files?

D

Dan

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.
 
M

Manohar Kamath

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).
 
S

Scott M.

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.
 
G

Guest

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
 
J

Juan T. Llibre

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
 
G

gaidar

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

Lau Lei Cheong

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.)
 
L

Lau Lei Cheong

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

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top