2.0 App-Code Folder Support for 'Code-Behind'

C

clintonG

I've posted to the forums but we're not making progress there yet so maybe,
just maybe somebody has this figured out...


When VS2005 creates a new Web Form with code placed in a separate file we
get the following:

WebForm1.aspx
WebForm1.aspx.cs

Both files are in the root of the project directory. I move WebForm1.aspx.cs
to the App_Code folder.

To test I declared Label1 in WebForm1.aspx and attempt to modify the Label1
text property as Label1.Text = Hello World"; in the Page_Load event of
WebForm1.aspx.cs but an error results.

Apparently moving the .cs files to App_Code folder not supported?
We've tried pathing and using the new page directive syntax but perhaps
incorrectly?
Any comments on this? It seems broken as all code is 'sposta' be within a
partial class so why wouldn't the compiler know how to cope when the .cs
files are moved to the App_Code folder?


<%= Clinton Gallagher
 
A

Arjen

Hi Clinton,

Look in the WebForm1.aspx file at line one "... CodeFile="WebForm1.aspx.cs"
....", is this correct?

Nope, change it to App_Code\WebForm1.aspx.cs.

Hope this helps,
Arjen
 
B

Brock Allen

The App_Code is meant for non-codebehind related code, if that makes sense.
So shared common functionality that's not specific to any one page. The compilation
model in ASP.NET 2.0 doesn't prefer the codebehind file in the App_Code folder.
As you've discovered, it wants the codebehind just in the same directory.

Now, you *can* move it there if you'd like, but then you should remove the
CodeFile attribute from your ASPX. This, unfortunately, will disable the
partial support and thus the automatic server side control declarations in
the codebehind.
 
C

clintonG

It looks like partial classes really are 'partial' when a 'part' must be
here and a 'part' must be there. :)

<%= Clinton Gallagher
 

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,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top