code behind problems in vs.net 2003

G

Girish

hey all,

im building a asp.net project in vs.net. Is there a way to have the
codebehind files sit in a different folder outside the website folder
altogether?

example:
The aspx files are in this directory
c:\inetput\wwwroot\testapp

the code behind code must be in this directory
c:\projects\testapp\src\com\tietronix\testapp\codebehind

where the namespace is "com.tietronix.testapp.codebehind"

I have tried these steps with no success.
1) changed the namespace in the aspx.cs file to the appropiate one.
2) changed the @page decl to

Page language="c#"
Codebehind="c:\projects\testapp\src\com\tietronix\testapp\codebehind\WebForm
1.aspx.cs" AutoEventWireup="false"
Inherits="com.tietronix.virtualastronaut.codebehind.WebForm1"


If this is possible outside of vs.net using a simple text editor - that
would be great as well.

Since im new to the namespace and codebehind concepts, id really appreciate
it if i could get a example that i was able to see.

thanks in advance for your help!
girish
 
J

Jiange Sun [MSFT]

Hi,

You can certainly change the default namespace name to fit your needs. But
you can not change the location of the code behind file by modifying the
CodeBehind to includes the full path. This is the MSDN doc for CodeBehind
Attribute:
****************************************************************************
******************************
CodeBehind
Specifies the name of the compiled file that contains the class associated
with the page. This attribute is used by the Visual Studio .NET Web Forms
designer. It tells the designer where to find the page class so that the
designer can create an instance of it for you to work with at design time.
For example, if you create a Web Forms page in Visual Studio called
WebForm1, the designer will assign the Codebehind attribute the value of
WebForm1.aspx.vb, for Visual Basic, or WebForm1.aspx.cs, for C#. This
attribute is not used at run time.
****************************************************************************
*******************************

You should not keep aspx and codebehind source file in seprate folders.
Both of them are part of a page entity.

Jiange Sun

Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only.
 
S

Steven Cheng[MSFT]

Hi Girish,

Thanks for posting in the community! From your description, you'd like to
set the codebehind file and the aspx file in separate folders, also you're
wanting some information or guides on using the code-behind file when
developing ASP.NET web page.

As for the first question, I quite agree with Jiange's suggestion. Since
the codebehind file is generated for us help develop the web pages more
conveniently at design time, it's better to make them together within the
same location.
And I've searched some references and tech articles on the description and
how to use the "code-behind" mode to develop ASP.NET web pages with VS.NET,
you may have a check to see whether they're helpful to you. Here are the
web links to them:

#Web Forms Code Model
http://msdn.microsoft.com/library/en-us/vbcon/html/vbconWebFormsCodeModel.as
p?frame=true

#Developing User Controls in a Code-Behind File
http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondevelopingusercont
rolsincode-behindfile.asp?frame=true

#INFO: ASP.NET Code-Behind Model Overview
http://support.microsoft.com/default.aspx?scid=kb;en-us;303247

#HOW TO: Work with Code-Behind Class Files in an ASP.NET Application by
Using Visual C# .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;308143

If you have any questions or need any further help, please feel free to
post here.



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

Girish

Thanks for the replies guys. I understand. Theres only one problem yet to be
ironed out in my mind. The code behind file is a class. Classes have
namespaces. For some reason I have a problem if I cant declare a class to be
in a namespace of my choice. I just cant seem to flush that from my system
that your not really supposed to do that.

If i want all source files to be in a namespace called
com.tietronix.testapp, how would i do that for the codebehind since it does
*not* sit in a directory structure of the format /com/tietronix/testapp BUT
sits in the web directory which is c:\inetpub\wwwroot\testweb

And thats another problem I have with VS.net. Why does it not allow me to
choose a directory on the local machine for my asp.net source files and on
build time - allow me to publish to a webserver? I want to isolate my source
files and my deployment files. Cause when you deploy, you dont need the
codebehind classes. you just need the assembly. I like to maintain this
directory structure since all my source files tend to sit in vss and src and
build files intermingling are just my pet peeves.

thanks. Im confused and I guess there is more than one q here.

If you cant answer them - thats ok. Everything slowly becomes clear anyways
after a few weeks of development. This is my first week of developing on the
..net platform.

thanks for your help.
girish
 
G

Girish

hmmmm

namespace has nothing to do with directory structure?
meaning if I had a namespace of com.tietronix.codebehind, the file declared
of that namespace need not be in a folder called
......./com/tietronix/codebehind/ ?

thanks,
girish
 
S

Steven Cheng[MSFT]

Hi Girish,


Have you viewed my last reply or have you got any ideas on this problem?
Please check out my suggestions in the last reply. If you need any further
help, please feel free to let me know.


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

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