ASP.NET Commerce Starter Kit Documentation
| # Visual Studio Project Notes (C#) Overview. This version of the Commerce Starter Kit application has been packaged as a Visual Studio .NET application, specifically a Visual C# .NET "ASP.NET Web Application" project. In addition to showing the Commerce Starter Kit application, this sample shows how to implement a real web application in VS.NET. Code-Behind. One of the big benefits of ASP.NET is a much more complete separation between static content (HTML, text and tags) from code. There are a couple of different ways to achieve this in ASP.NET. The SDK versions of the Commerce Starter Kit show the "single-file" approach, where code is in the same file as the static content, but segregated into a single code block. VS.NET, on the other hand, favors ASP.NET's code-behind model for separating code from content. This way, the page code is a fully encapsulated class which gets the full benefits of code editing in VS.NET: syntax color coding, statement completion, auto-insertion of event handling methods, design-time syntax checking and full debugging support. Note: It is possible to create, edit and debug single-file ASPX files in VS.NET, however most of the features listed above are not supported for code within a single-file ASPX file. To create a single file ASPX, select Project > Add New Item, and create a new Text file with the .ASPX extension. When you create a new ASP.NET page, or "Web Form," VS.NET creates both the .ASPX file, and the code-behind file. By default the code-behind file is hidden, but you can see it by selecting Project > Show All Files. To work with a Web Form in VS.NET, double-click the file name in Solution Explorer, or right-click and select one of the available actions. Open will open an ASPX file in design view, and a .CS file in code view. Open With permits you to select a different editor for the file, for example, Notepad. View Code always opens the code-behind for the selected file (even when the ASPX file is selected). Likewise, View Designer always opens the ASPX file. The Web Forms designer also uses the <%@ Page %> directive (or <%@ Control %> directive for user controls) to associate the two files. Minimally, code-behind ASP.NET pages and user controls created in VS.NET need the following attributes:
        <%@ Page Language="c#" AutoEventWireup="false" Codebehind="WebForm1.aspx.cs" Inherits="PortalVS.WebForm1"%>

        <%@ Control Language="c#" AutoEventWireup="false" Codebehind="myControl.ascx.cs" Inherits="PortalVS.myControl"%>
AutoEventWireup. This should be false for VS.NET code-behind pages and user controls. Setting AutoEventWireup to false disables the automatic Page wireup of page events when a specially named method is found in the code (for example, Page_Load). VS.NET always creates the page event wireup explicitly in code. Codebehind. This is a design-time only attribute used by the Web Forms designer. Inherits. This is used at runtime to associate the code in the code-behind class with the code generated from the ASPX file. Project Properties. In a Visual C# application, the .NET namespace for the code in the project is provided by the Project Properties, as is the name of the assembly to build. In this project, the assembly name is set to "Portal." The Default namespace is not set, which permits the developer to choose the namespace explicitly on a per-file basis. To see this, examine Project > Properties. Another interesting feature of Project Properties is the ability to specific Imports statements at the project level. This reduces the code in each code file by several lines. Compiling and Running the Application. Changes to the code-behind class must be compiled prior to running the page. You can compile using the Build > Build command. Tip: The Ctrl-F8 keyboard shortcut (Build and Browse) will both compile the project and launch the selected page in the browser. To browse the application in a browser, right-click the Default.aspx file, and select one of the Browse options. View in Browser (Alt-V) will open the page in the default browser within VS.NET. Browse With... lets you select an external browser, and even set it as your "View in Browser" default. To launch the application in the debugger, first set your breakpoints. Then right click an appropriate page and select Set As Start Page. Then you can press F5 to launch the debugger.