473,378 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Auto-Comilation of .CS classes???

I love that I can create ASPX and ASCX files with CS code embedded or in code-behind files and ASP.NET will auto-compile it all for me. I *like* it that way

Is there ANY way to have classes defined in .cs files somewhere and have them accessed by my ASPX, ASCX, and Code-Behind files WITHOUT having to manually compile them first???
Nov 18 '05 #1
11 1657
Hi,

Based my understanding, does the problem you mentioned as:
"Is there ANY way to have classes defined in .cs files somewhere and have
them accessed by my ASPX, ASCX, and Code-Behind files WITHOUT having to
manually compile them first???"

means that you just want to provide a certain .cs codebehind class's source
file for a aspx page or ascx control without compiling the cs file into
assembly and let them be compiled at runtime when the certain page or ascx
control is requested, yes?

If so, I think you can use the "Src" attribute in the @Page or @Control
directive, for example:
<%@ Page language="c#" Src="xxx.cs" >
<%@ Control Language="c#" Src="xx.cs" >

The "Src" will make the code-behind class files be compiled on demand
instead of precompiled. And
the "Src" attribute is listed with the relative path of the code-behind
class file (SrcSample.aspx.cs), and that the Inherits attribute value is
set to reference the certain class(classname with full namespace). In
addition, when you use the "Src" attribute to make the code-behind class
compiled at runtime on demand, you must make sure no precompiled classes in
the existing assemblies in the web application's reference path, othewise,
you'll encounter some unexpected errors. For detailed info, please refer to
the following kb articles:

#INFO: ASP.NET Code-Behind Model Overview
http://support.microsoft.com/?id=303247

#HOW TO: Work with Code-Behind Class Files in an ASP.NET Application by
Using Visual C# .NET
http://support.microsoft.com/?id=308143

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #2
Steven,

Not to speak for Alex :) but, I believe his problem is similar to mine
(which is posted a few hours ago as subj: JIT assemblies)...

Basically, the problem is not using "compile on demand" (via specifying
SRC), it's using _other_ "compile on demand" classes from the code behind
class. In short, I can do this in the .aspx page simply by using a
@Assembly directive (src="mytestfile.cs") ... but, how to do this from the
CodeBehind? Is there a way to build a reference to the .cs file?

To copy my example below, assume the following testclass.cs file, that is
compiled on demand:

namespace testnamespace
{
public class testclass
{
public static string teststring = "contents of teststring";
public testclass()
{
}
}
}

If I have a page w/o a code behind, I can access this class using:
<%@ Assembly Src="testclass.cs" %>
....
<%
Response.Write(testnamespace.testclass.teststring) ;
%>

Can you show me how to use this class from a code behind (that is compiled
on demand)?

Brian


"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:bx**************@cpmsftngxa06.phx.gbl...
Hi,

Based my understanding, does the problem you mentioned as:
"Is there ANY way to have classes defined in .cs files somewhere and have
them accessed by my ASPX, ASCX, and Code-Behind files WITHOUT having to
manually compile them first???"

means that you just want to provide a certain .cs codebehind class's source file for a aspx page or ascx control without compiling the cs file into
assembly and let them be compiled at runtime when the certain page or ascx
control is requested, yes?

If so, I think you can use the "Src" attribute in the @Page or @Control
directive, for example:
<%@ Page language="c#" Src="xxx.cs" >
<%@ Control Language="c#" Src="xx.cs" >

The "Src" will make the code-behind class files be compiled on demand
instead of precompiled. And
the "Src" attribute is listed with the relative path of the code-behind
class file (SrcSample.aspx.cs), and that the Inherits attribute value is
set to reference the certain class(classname with full namespace). In
addition, when you use the "Src" attribute to make the code-behind class
compiled at runtime on demand, you must make sure no precompiled classes in the existing assemblies in the web application's reference path, othewise,
you'll encounter some unexpected errors. For detailed info, please refer to the following kb articles:

#INFO: ASP.NET Code-Behind Model Overview
http://support.microsoft.com/?id=303247

#HOW TO: Work with Code-Behind Class Files in an ASP.NET Application by
Using Visual C# .NET
http://support.microsoft.com/?id=308143

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #3
Steve

So close, but not quite what I meant. I know how to have ASP.NET automatically compile the code-behind .cs filr for my ASPX or ASCX. My problem is that I want to create a few utility classes that are used around my site and called from within some of those code-behing .cs pages, etc. But I don't want to have to pre-compile those utility classes. Do I absolutely HAVE to precompile a .CS stand-alone class to use it from other .ASPX, .ASCX, and Code-Behind .CS files

And if I *do* have to pre-compile them, I'm just curious as to why I have to when I don't have to manually pre-compile the ASPXs and their code-behind .CS files

Thanks

Ale

----- Steven Cheng[MSFT] wrote: ----

Hi

Based my understanding, does the problem you mentioned as
"Is there ANY way to have classes defined in .cs files somewhere and have
them accessed by my ASPX, ASCX, and Code-Behind files WITHOUT having to
manually compile them first???

means that you just want to provide a certain .cs codebehind class's source
file for a aspx page or ascx control without compiling the cs file into
assembly and let them be compiled at runtime when the certain page or ascx
control is requested, yes

If so, I think you can use the "Src" attribute in the @Page or @Control
directive, for example
<%@ Page language="c#" Src="xxx.cs" ><%@ Control Language="c#" Src="xx.cs"

The "Src" will make the code-behind class files be compiled on demand
instead of precompiled. An
the "Src" attribute is listed with the relative path of the code-behind
class file (SrcSample.aspx.cs), and that the Inherits attribute value is
set to reference the certain class(classname with full namespace). In
addition, when you use the "Src" attribute to make the code-behind class
compiled at runtime on demand, you must make sure no precompiled classes in
the existing assemblies in the web application's reference path, othewise,
you'll encounter some unexpected errors. For detailed info, please refer to
the following kb articles

#INFO: ASP.NET Code-Behind Model Overvie
http://support.microsoft.com/?id=30324

#HOW TO: Work with Code-Behind Class Files in an ASP.NET Application by
Using Visual C# .NE
http://support.microsoft.com/?id=30814

Regards

Steven Chen
Microsoft Online Suppor

Get Secure! www.microsoft.com/securit
(This posting is provided "AS IS", with no warranties, and confers no
rights.

Get Preview at ASP.NET whidbe
http://msdn.microsoft.com/asp.net/whidbey/default.asp
Nov 18 '05 #4
Hi Alex,

Thanks for the response. I've noticed that this issue is related with
another one whose titile is
"Accessing Parent Page members from a UserControl"

I've posted my reply there and provided my suggestions on this issue. Since
the classes imported in a certain source file need to be contained in a
compiled assembly so that the certain util assembly can reference it. I'm
afraid you need to make the "BasePage" recompiled. And as for the pages'
"Src" attribute, we have to specify another page class rather than the
"BasePage", maybe a class derviced from the "BasePage" Class. Please have a
look and if you have any other concerns, please feel free to post here.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #5
Steven could you answer my question above in this thread and below (under
JIT assemblies)? I'm dying for an answer on this one :)

This solution somewhat answers it, but not exactly. It must be technically
feasible, though perhaps not possible, to reference JIT classes from other
JIT classes....

-Brian

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:4L*************@cpmsftngxa06.phx.gbl...
Hi Alex,

Thanks for the response. I've noticed that this issue is related with
another one whose titile is
"Accessing Parent Page members from a UserControl"

I've posted my reply there and provided my suggestions on this issue. Since the classes imported in a certain source file need to be contained in a
compiled assembly so that the certain util assembly can reference it. I'm
afraid you need to make the "BasePage" recompiled. And as for the pages'
"Src" attribute, we have to specify another page class rather than the
"BasePage", maybe a class derviced from the "BasePage" Class. Please have a look and if you have any other concerns, please feel free to post here.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #6
Steve (and Brian)

Brian has it *exactly* right. For the moment, let's re-state the question like this

You have three files
1. AnyPage.asp
2. AnyPageCodeBehind.c
3. UtilClass.c

AnyPage.aspx has an "<%@Page" directive setting up "AnyPageCodeBehind.cs" as the code-behind source for AnyPage.asp

INSIDE the AnyPageCodeBehind.cs file (as well as from other .cs files around my site), I want to create and use the class and members from the UtilClass.cs file

THE QUESTION IS, DO I *HAVE* TO PRE-COMPILE UtilClass.cs IN ORDER TO ACCESS ITS CLASSES AND MEMBERS FROM OTHER .CS FILES OR IS THERE *ANY* WAY AT ALL TO REFERENCE IT FROM A .CS FILE SO THAT IT WILL BE AUTO-COMPILED??

Hope this clears up the question

Ale

----- Brian H wrote: ----

Steven

Not to speak for Alex :) but, I believe his problem is similar to min
(which is posted a few hours ago as subj: JIT assemblies)..

Basically, the problem is not using "compile on demand" (via specifyin
SRC), it's using _other_ "compile on demand" classes from the code behin
class. In short, I can do this in the .aspx page simply by using
@Assembly directive (src="mytestfile.cs") ... but, how to do this from th
CodeBehind? Is there a way to build a reference to the .cs file

To copy my example below, assume the following testclass.cs file, that i
compiled on demand

namespace testnamespac

public class testclas

public static string teststring = "contents of teststring"
public testclass(

If I have a page w/o a code behind, I can access this class using
<%@ Assembly Src="testclass.cs" %
...
<
Response.Write(testnamespace.testclass.teststring)
%

Can you show me how to use this class from a code behind (that is compile
on demand)

Bria


"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in messag
news:bx**************@cpmsftngxa06.phx.gbl..
Hi
Based my understanding, does the problem you mentioned as "Is there ANY way to have classes defined in .cs files somewhere and hav
them accessed by my ASPX, ASCX, and Code-Behind files WITHOUT having t
manually compile them first???
means that you just want to provide a certain .cs codebehind class'

sourc file for a aspx page or ascx control without compiling the cs file int
assembly and let them be compiled at runtime when the certain page or asc
control is requested, yes
If so, I think you can use the "Src" attribute in the @Page or @Contro directive, for example
<%@ Page language="c#" Src="xxx.cs" >><%@ Control Language="c#" Src="xx.cs" >>> The "Src" will make the code-behind class files be compiled on deman
instead of precompiled. An
the "Src" attribute is listed with the relative path of the code-behin
class file (SrcSample.aspx.cs), and that the Inherits attribute value i
set to reference the certain class(classname with full namespace). I
addition, when you use the "Src" attribute to make the code-behind clas
compiled at runtime on demand, you must make sure no precompiled classe

i the existing assemblies in the web application's reference path, othewise
you'll encounter some unexpected errors. For detailed info, please refe t the following kb articles
#INFO: ASP.NET Code-Behind Model Overvie

http://support.microsoft.com/?id=30324
#HOW TO: Work with Code-Behind Class Files in an ASP.NET Application b

Using Visual C# .NE
http://support.microsoft.com/?id=30814
Regards
Steven Chen

Microsoft Online Suppor
Get Secure! www.microsoft.com/securit

(This posting is provided "AS IS", with no warranties, and confers n
rights.
Get Preview at ASP.NET whidbe

http://msdn.microsoft.com/asp.net/whidbey/default.asp

Nov 18 '05 #7
Hi Alex,

Thanks for the reply and the restate of the problem.
I've got that your questions is actually focus on
"How to make a certain cs file be referenced without recompiled and will be
compiled at runtime when requested"

As for this problem, I think the certain cs file need to be precompiled
into assembly first. Because you reference it in the codebehind cs file
rather than an aspx page. In other word, it is just like we reference a
class in assembly B from a class in assembly A. If the assembly B's source
code is not precompiled into assembly, when the assembly A is compiling ,
it'll occur error finding the certain reference. And as for the "Src"
attribute of the @Page directive which can cause the codebehind class be
auto-compiled at runtime, this is a certain feature provided by
ASP.NET(when a PAGE is requested) only not for common .net senario. So if
we want to reference a certain class from a external assembly(separate from
the caller class's assembly), we have to precompiled it into assembly first.

In addition, would you please tell use the reason why you'd like to put the
utitlity classes non-precompiled until runtime, is it frequently changed or
for any other concerns? Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #8
Hi Brian,

As far as I known, there isn't any @directive which can help make the any
referenced source file auto-compiled at runtime in a codebehind( source
file). The @Assembly or @Page diretive which can make a assembly or
codebind 's source auto-compiled is provided by the ASP.NET runtime which
also make use of the System.Runtime.CompilerServices components
internally. So I think if you'd like to reference a certain class in
codebehind, you need to have the certain precompiled assembly. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #9
I'm feeling invisible here ... can I jump in?

The thing is, though, you can sort-of do it in ASPX page using the "assembly
src=blah.cs" directive. Blah.cs will then be compiled.

Where this is a problem, for me, is that I have several user controls. For
example, suppose I have Product.aspx and Product.aspx.cs. Suppose I have
ProductDetail.ascx and ProductDetail.ascx.cs, Alternate.ascx and
Alternate.ascx.cs. If I want to load these controls dynamically from
Product.aspx and cast them as types defined within these controls, I cannot
do it without precompiling. I can post code if it would help.

-Brian
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:p5*************@cpmsftngxa06.phx.gbl...
Hi Alex,

Thanks for the reply and the restate of the problem.
I've got that your questions is actually focus on
"How to make a certain cs file be referenced without recompiled and will be compiled at runtime when requested"

As for this problem, I think the certain cs file need to be precompiled
into assembly first. Because you reference it in the codebehind cs file
rather than an aspx page. In other word, it is just like we reference a
class in assembly B from a class in assembly A. If the assembly B's source
code is not precompiled into assembly, when the assembly A is compiling ,
it'll occur error finding the certain reference. And as for the "Src"
attribute of the @Page directive which can cause the codebehind class be
auto-compiled at runtime, this is a certain feature provided by
ASP.NET(when a PAGE is requested) only not for common .net senario. So if
we want to reference a certain class from a external assembly(separate from the caller class's assembly), we have to precompiled it into assembly first.
In addition, would you please tell use the reason why you'd like to put the utitlity classes non-precompiled until runtime, is it frequently changed or for any other concerns? Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #10
Thanks for the reply, Steve!

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:r9**************@cpmsftngxa06.phx.gbl...
Hi Brian,

As far as I known, there isn't any @directive which can help make the any
referenced source file auto-compiled at runtime in a codebehind( source
file). The @Assembly or @Page diretive which can make a assembly or
codebind 's source auto-compiled is provided by the ASP.NET runtime which
also make use of the System.Runtime.CompilerServices components
internally. So I think if you'd like to reference a certain class in
codebehind, you need to have the certain precompiled assembly. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #11
Hi Alex,

Have you got any further ideas on this issue? If you have anything unclear
or if there're anything else we can help, please feel free to post here.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Nov 18 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code...
1
by: Glabbeek | last post by:
I'm changing the layout of my site. Instead of using tables, I will use DIVs. It's working fine, except for 1 thing: In IE6 some DIVs are not the correct width. Mozilla and Opera are showing the...
5
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge...
20
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
5
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the...
5
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if...
22
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
2
by: Piotr K | last post by:
Hi, I've encountered a strange problem with Firefox which I don't have any idea how to resolve. To the point: I've <divelement with a style "height: auto" and I want to retrieve this value...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.