CodeFile vs CodeBehind - asp.net

What is the difference between CodeFile="file.ascx.cs" and CodeBehind="file.ascx.cs" in the declaration of a ASP.NET user control?
Is one newer or recommended? Or do they have specific usage?

CodeBehind: Needs to be compiled (ASP.NET 1.1 model). The compiled binary is placed in the bin folder of the website. You need to do a compile in Visual Studio before you deploy. It's a good model when you don't want the source code to be viewable as plain text. For example when delivering to a customer to whom you don't have an obligation to provide code.
CodeFile: You provide the source file with the solution for deployment. ASP.NET 2.0 runtime compiles the code when needed. The compiled files are at Microsoft.NET[.NET version]\Temporary ASP.NET Files.

I'm working with an Application Project in Visual Studio Express 2012 For Web and using .NET 4.0. In the code behind files for my login and change password pages I found a situation where I needed both CodeBehind and CodeFile in the declaration.
If I don't add a code file reference like
CodeFile=login.aspx.cs
The web page doesn't parse and the browser displays a parser error. It doesn't matter whether I compile the project or not.
If I don't add a code behind reference like
CodeBehind=login.aspx.cs
References to Security classes like MembershipUser fail both at compile time and when attempting to use intellisense with an error like "The type or namespace MembershipUser cannot be found". I have added a reference to System.Web.ApplicationServices as required by the .Net 4.0 framework.
I should add that these troublesome files are running in an application within the website created using the IIS Application tool. When I open the website from Visual Studio I have no difficulty with parser errors or reference errors. This confusion only occurs when I open the application as a project in Visual Studio.

Codebehind file need to compile before run but in src we dont need to compile and then run.. just save the file.

Related

unrecognized tag-prefix in my project in asp.net control

I'm having a major problem in my project that all the asp.net controls having error of unrecognized tag-prefix because of the all the internal tag has been converted to lower case and intellisense is not working on these control but working on html controls, this project is working fine on other system but not on my system. Other projects on my system are working fine.
I have done the following things but didn't find the solution for it:
Deleted reflected schema from vs folder
Add tag for the asp control in web.config
Formatted my system.
Added the intellisense .js file.
Done the VS repair
Hoping for the positive solution. Thanks in advance
Delete the C:\Users\UserName\AppData\Roaming\Microsoft\VisualStudio\10.0 folder:
Visual Studio 2010 RTM intellisense not working for asp.net tags

How do I make Visual Studio "compile" a .aspx file?

In my ASP.NET MVC application I have a .aspx file. I select it in Visual Studio 2010 Project Explorer tree and go to file properties - the "Build Action" is set to "Content". I change "Build Action" to "Compile" and ask Visual Studio to build the project. I get the following error message for my .aspx file in the compiler output:
C:\PathToProject\MyFile.aspx(1,1): error CS0234: The type or namespace name 'global_asax'
does not exist in the namespace 'ASP' (are you missing an assembly reference?)
the first line of the .aspx file is:
<%# Page Language="C#" MasterPageFile="~/Views/Shared/My.Master" Inherits="System.Web.Mvc.ViewPage" %>
which makes me wonder...
What is the compiler trying to complain about and how do I make it compile the .aspx file?
The view's .aspx must have its Build Action set to Content.
To enable pre-compilation (or, at least, compiler error checks) at build time, add
<MvcBuildViews>true</MvcBuildViews>
to the first <PropertyGroup> in your .csproj.
As #KennyZ says, ASPX/ASCX/Master/CSHtml files are not "compiled" - not as part of the regular build process anyway. That's because these files are compiled into Page classes on first-request, this is to allow webmasters to modify the files on-the-go, which is generally speaking a good idea, especially if the ASPX files contain a lot of content.
Note that the VS File Properties Build Action does not control this setting - I think the BuildAction property should be hidden or at least better documented - it isn't very well understood by the developer community.
But it can be done! In VS2005 when they introduced the ill-fated "web site" projects (as a replacement for VS2003 "Web Applications" until VS2005 SP1 came out) there was an option to pre-compile the ASPX/ASCX/Master files into the application's assembly - it did leave behind stub *.aspx files that didn't contain any content, but instead referenced the pre-compiled page classes.
You can still do this with VS2010, but you need to use the command-line aspnet_compiler.exe as the GUI for it doesn't exist for Web Application projects.
There is more documentation available here: http://msdn.microsoft.com/en-us/library/bb398860%28v=vs.100%29.aspx
and here: http://msdn.microsoft.com/en-us/library/ms229863%28v=vs.100%29.aspx

F# the namespace or module 'XXXX' is not defined

I'm trying to create a basic ASP.net f# application and when I'm trying to reference the Youtube .net API I'm getting a "The namespace or module 'Google' is not defined" in my code behind file.
I've used the default ASP web forms template in Visual Studio, removed all of the contents, then loaded in the examples from Expert F#, Chapter 14. The default examples run fine, the problem only occurs when loading the Google API. The API works fine when I load it through an f# console application.
The first few lines behind file looks like:
#light
namespace MyASPApp
open System
open System.Web
open System.Web.UI
open System.Web.UI.WebControls
open Google.YouTube
Can anyone think of a resolution to the problem, or anything I could check to understand why its not picking up the Google API?
The Google assembly may require that the application not use the Client Profile, which is the default in VS 2010. Try editing the project settings and changing the Target Framework property.
Did you check which version of .NET Framework that google assembly is built for? If it .NET 3.5 or .NET 4.0? If that is not set properly too this will occur.
-Fahad

Compiling the whole asp.net website on Mono at once

i am compiling the asp.net web application page by page using "gmcs" command in Mono.
But i want to compile the whole asp.net website at once using Mono command.
For ex:
gmcs /t:library /out:bin/AJAX.dll -r:System.dll -r:System.Web.dll -r:bin/AjaxControlToolkit.dll Default.aspx.cs Default.aspx.designer.cs
I do not want to do like the above one, instead i want to compile the whole folder containing files at once.
Plz let me know.thanks in advance
I used to run xbuild on projects created using Visual Studio as IDE. Worked perfectly! I'm not sure if MonoDevelop generates a .csproj file for your web application but that's the best way to compile ASP.NET, which, however, was supposed to be compiled automatically by xsp on the first request

ASP.NET 2.0 application won't compile when adding a Microsoft Report to the solution

I have a ASP.NET 2.0 web application. To that solution I add a Report (Reporting Services).
I make no further changes to that report. When I try build the application the build fails with the following error originating from that report file:
A namespace does not directly contain members such as fields or
methods
The problem was Visual Studio. I've restarted the IDE and could compile the application without problems.

Resources