Is it possible to Import a .cs file to my aspx page?

B

Blue Ball

In my aspx page, I want to import a .cs file, but I don't want to compile to
dll. Is it possible?

I know that codebehind can do it in Page level, but it forces me to use
inherits which I don't want to:
@Page Inherits="code.page" src="code.cs"

In this case, my code.cs has to inherits from System.Web.UI.Page.

As far as I know, @Import directive only works with dll. it seems not
able to import a source file

Is is possible to just import the class (from a .cs file) to my aspx page?
 
S

Sebastien Lambla

Blue said:
In my aspx page, I want to import a .cs file, but I don't want to compile to
dll. Is it possible?

I know that codebehind can do it in Page level, but it forces me to use
inherits which I don't want to:
@Page Inherits="code.page" src="code.cs"

In this case, my code.cs has to inherits from System.Web.UI.Page.

As far as I know, @Import directive only works with dll. it seems not
able to import a source file

Is is possible to just import the class (from a .cs file) to my aspx page?

You cannot "import" .net code as it needs to be compiled as a dll at one
point or another. Two questions though:
1. Why don't you want to use this file as the parent class for your aspx
page? Because you have a different one?
2. If it is the case, are you just trying to be able to create objects
and access their methods from your aspx and your code behind page?

If yes, then you should just add the .cs file into a project on its own
and compile it, and reference it from your web application.
 

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

Top