Last post Apr 21, 2010 09:52 PM by smar1216
Jan 16, 2008 06:36 PM|frost|LINK
Ok this is a little unsettling. Just recently we spent alot of time and effort converting a vs 2003 .net 1.1 project to vs 2005 .net 2.0 Web Application project with the use of the 'Convert to Web application' tool that is provided in vs 2005. There were
loads of errors and we painstakingly fixed them.
In that original conversion one of the things we researched and found we were to convert was to use CodeFile instead of Codebehind in our aspx pages because the CodeFile allowed for partial postbacks in .net 2.0 so we did. Along the way we found that the
aspx pages in our project didn't work even though we copied the compiled dll to the server. We always had to then bring the .vb files with the aspx pages or it wouldn't work; this is something we never did before the conversion.
We have now taken that project and we're using vs 2008 with the .net 3.5 framework, so today (by chance when trying to solve a different issue) I had created a new aspx page and copied it to our server along with the compiled project dll and low and behold
it failed. It said I needed to have the .vb page as well on the server for the aspx page to work. I got to looking around and changed the Codefile back to Codebehind, recompiled the project and took only the .dll to the server and it worked!!!
So, my question is what is correct? Are we supposed to be using CodeFile or Codebehind in our aspx pages? If we use Codefile we need the .vb files, and if we use Codebehind we only need the compiled .dll which is what we want. But I want to know what
is correct for .Net 3.5?
Jan 17, 2008 03:20 AM|ngaisteve1|LINK
What I know is if you create a web application in visual studio 2005, you don't need to compile to run it. You just run it like classic asp. (interpret)
But, in visual studio 2005, it also allow you to create a project. If you create a
project, you need to compile it and it will run from the compiled dll code.
Correct me if I'm wrong.
Jan 17, 2008 12:29 PM|frost|LINK
So when we initially migrated from 1.1 to 2.0 we didn't need to use the 'Convert to Web Application' feature as that just makes it so you need the vb files and that's why it will run without compiling the code.
That is less than ideal since you are then required to maintiain the aspx page, and vb on the server instead of just the aspx page and dll file. If we change all the Codefile references back to Codebehind does this effect the partial postback abilities
in the updated .net framework?
I guess I need to know why people change this, and is it require or is it going to be the new standard for developing .Net projects. There is alot of information out there that contradics each other and I have yet to find a solid answer about it all.
Jan 17, 2008 09:17 PM|ngaisteve1|LINK
I think I don't really know how to answer your question. But I found this article -
Hope you find it useful.
Jan 18, 2008 11:51 AM|frost|LINK
Thanks for the article, it does explain a little more about it. This issue I've raised nobody seems to know the answer to it for whatever reason. I'd like to know what other people are doing out there for their web applications.
Apr 21, 2008 04:18 AM|yaqoob|LINK
I had the same problem converting a VS2005 web site project to a web application. At some point I found out about the CodeFile change and religiously changed all Codebehind attributes to CodeFile. Unfortunately that was part of a bigger set of changes, so
it took me a while to find out that it'll only build and run correctly with Codebehind. I think the issue is that when VS2005 came out, it didn't cater for web applications, then MS added the support in Service Pack 1, but most of the documentation assumes
you have a web site rather than a web application, and the web application support requires the Codebehind attribute, to avoid ASP.NET creating an assembly per page on the fly, which seemed to be the problem I hit.
Apr 21, 2008 10:47 AM|frost|LINK
Well that explains some of my problem, what was the end result for you? Did you revert all the codefile tags back to the previous codebehind?
Apr 21, 2008 11:16 AM|yaqoob|LINK
Yes, that's the only way I could get it to work as a web application, which is what we wanted.
Aug 09, 2008 10:51 PM|hchattaway|LINK
Have you been able to nail down this behavior? What standard have you adopted? I too just found this issue and Googled it and found this thread. I changed my pages back to use "codebehind" so I do not have to copy over the "cs" file. Kind of defeated the
purpse of compiling it into the DLL when using the WAP!
Aug 12, 2008 05:14 AM|yaqoob|LINK
All we've done is to stick to Codebehind as that works and gives the desired results. Not very scientific, but it does the job! As to the whole story, it's probably buried in MSDN somewhere, but I haven't found it and am hoping that when we move to Visual
Studio 2008 all my troubles will be solved and life will be bliss :O)
Aug 13, 2008 11:40 AM|frost|LINK
I'm running VS 2008 with the same issues so unfortunately I haven't found the bliss you are looking for; I had hoped I would find that as well when going to vs 2008. We have went back to using codebehind as a standard and everything is back to the way it
should be (copying only compiled dll's) . I'm not sure why there isn't more literature on this subject from Microsoft, or should I say maybe there is but I haven't found it.
Aug 13, 2008 11:49 AM|yaqoob|LINK
Thanks for letting me know. I'm hoping we'll be moving to VS 2008 soon, especially now SP1 is out.
Dec 01, 2008 09:24 PM|mousedoc|LINK
According to the msdn website ( http://msdn.microsoft.com/en-us/library/ydy4x04a(VS.85).aspx), use CodeFile from now on. I suspect your issue may be that the Inherits attribute doesn't
contain a fully qualified domain name for the inherited class, but don't have a server to deploy to at the moment to check. Switching at least fixed some compiling issues I was having in VS2008.
Specifies the name of the compiled file that contains the class associated with the page. This attribute is not used at run time.
This attribute is included for compatibility with previous versions of ASP.NET, to implement the code-behind feature. In ASP.NET version 2.0, you should instead use the
CodeFile attribute to specify the name of the source file, along with the
Inherits attribute to specify the fully qualified name of the class.
Specifies a path to the referenced code-behind file for the page. This attribute is used together with the
Inherits attribute to associate a code-behind source file with a Web page. The attribute is valid only for compiled pages.
Dec 02, 2008 04:20 AM|yaqoob|LINK
Thanks for the extra info. I checked our pages and they all have a fully qualified class name as the Inherits value. I'm pretty sure this is a poorly documented feature of Microsoft's going back on themselves after only initially supporting web site projects
in VS2005 and then realising that the web site model doesn't suit every kind of project so they retrofitted the web application project support, and it requires CodeBehind instead of CodeFile. But without a specific steer from Microsoft, that's just a theory.
Dec 02, 2008 08:36 PM|mousedoc|LINK
You may/may not know what follows, but I think I've finally figured out my question of which to use and problems with being able to create web pages that use master pages in VS2008, sort of. Web Application Projects (WAP) generate one assembly for the website
and allow the use of multiple projects for modular website development and deployment. Website projects support editing of one page, XCOPY deployment of source (aspx plus underlying codebehind file), and recomplining only that updated page by the server on
demand. WAPs require recompilation of the entire website and deployment of the dll.
By default, adding pages to WAP's in VS use a Web Form template with CodeFile that allow selection of a master page, although the file can be manually changed to a masterpage user. The programmer can instead use the Web Content Form template. The Web Content
Form template uses CodeBehind. You can use Web Content Forms in a WAP, but a namespace is created in the code behind file and must be referenced in the Inherits attribute of the aspx page. WAP convention is that namespaces follow the folder structure in the
website and are period (.) separated.
Website projects only have a Web Form template and support selecting masterpages. Namespaces also follow the site folder structure but use an underscore (_) rather than period (.) resulting in one giant namespace for the app. So, the aspx page references
no namespace in the Inherits attribute. The template creates a CodeFile attribute. Pages compile without error using both CodeFile and CodeBehind.
From what I can tell, but CodeFile and CodeBehind compile without errors. Because of the compile on demand feature of Website projects, the source code page must tag along, I think. If you create 2 apps, one WAP and one Website and do some deploying to a
live server I'm wondering if the project type is not the difference as much as CodeFile vs. CodeBehind. But I could be all wrong...
The followng two articles were helpful to me and have me leaning towards using WAP for pretty much all my group efforts, although I like the ease of the website project during solo development.
Dec 03, 2008 03:58 AM|yaqoob|LINK
I had read those articles, but not carefully enough to glean the information you've presented - thanks once again for doing the leg work! I think when we finally move to VS2008 I'll re-visit this in the light of what you've said above. For a standalone product
like the one I wok on, web application is absolutely the right choice, but I can see how a web site project would be much more useful in a more dynamic and frequently changing environment.
Dec 03, 2008 10:40 PM|frost|LINK
Thanks for the continued information on this issue. I do believe by using codebehind we are not taking advantage of the partial page postbacks and as such missing out on Ajax functionality that should otherwise be a nice development touch. I'll read your
articles posted and let you know what comes of it all.
Apr 21, 2010 09:49 PM|smar1216|LINK
Sorry, but you are wrong.
A "Web Application Project" requires the code to be built as has been the case since ASP .NET 1.0. An "ASP .NET Web Site" does not have to be precomplied. "Web Sites" are not projects, but "Web Applications" are.
Apr 21, 2010 09:52 PM|smar1216|LINK
There was no need for you to use the "Convert to Web Application" feature in the first place, since you were already working with an ASP.NET 1.1 Web Application. That feature is to take an ASP .NET Web "Site" and convert it to an ASP .NET "Web Application
Project". You already were working with a project. Also, you state that you wanted to do this because it would allow you to use partial page updates, but that is not correct. Partial page updates are a feature of ASP .NET AJAX and can be utilized in both
Web Sites and Web Application Projects. What moving to CodeFile vs. CodeBehind does is allow you to use partial classes.