asp.net full details

Upload: satish-kumar

Post on 06-Apr-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 ASP.net Full Details

    1/52

    Tutorial 1: Building Your First Web

    Application Project

    The below tutorial walks-through how to create, build and run your first web app using C#

    and the ASP.NET Web Application Project support in VS 2005.

    Creating a New Project

    Select File->New Project within the Visual Studio 2005 IDE. This will bring up the NewProject dialog. Click on the Visual C# node in the tree-view on the left hand side of thedialog box and choose the "ASP.NET Web Application" icon:

    Choose where you want the project to be created on disk (note that there is no longer arequirement for web projects to be created underneath the inetpub\wwwroot directory -- soyou can store the project anywhere on your filesystem). Then name it and hit ok.

    Visual Studio will then create and open a new web project within the solution explorer. Bydefault it will have a single page (Default.aspx), an AssemblyInfo.cs file, as well as aweb.config file. All project file-meta-data is stored within a MSBuild based project file.

  • 8/3/2019 ASP.net Full Details

    2/52

    Opening and Editing the Page

    Double click on the Default.aspx page in the solution explorer to open and edit the page. Youcan do this using either the HTML source editor or the design-view. Add a "Hello world"header to the page, along with a calendar server control and a label control (we'll use these ina later tutorial):

    Build and Run the Project

  • 8/3/2019 ASP.net Full Details

    3/52

    Hit F5 to build and run the project in debug mode. By default, ASP.NET Web Applicationprojects are configured to use the built-in VS web-server (aka Cassini) when run. The defaultproject templates will run on a random port as a root site (for example:http://localhost:12345/):

    You can end the debug session by closing the browser window, or by choosing the Debug->Stop Debugging (Shift-F5) menu item.

    Looking under the covers

    When you compile/build ASP.NET Web Application projects, all code-behind code,embedded resources, and standalone class files are compiled into a single assembly that is

    built in the \bin sub-directory underneath the project root (note: you can optionally change thelocation if you want to - for example, to build it into a parent application directory).

    If you choose the "Show All Files" button in the solution explorer, you can see what the

    result of our compilation output looks like:

  • 8/3/2019 ASP.net Full Details

    4/52

    This works exactly the same as with Visual Studio 2003 ASP.NET Web Application Projects

    Customizing Project Properties

    ASP.NET Web Application Projects share the same configuration settings and behaviors asstandard VS 2005 class library projects. You access these configuration settings by right-clicking on the project node within the Solution Explorer in VS 2005 and selecting the"Properties" context-menu item. This will then bring up the project properties configurationeditor. You can use this to change the name of the generated assembly, the build compilationsettings of the project, its references, its resource string values, code-signing settings, etc:

  • 8/3/2019 ASP.net Full Details

    5/52

    ASP.NET Web Application Projects also add a new tab called "Web" to the projectproperties list. Developers use this tab to configure how a web project is run and debugged.By default, ASP.NET Web Application Projects are configured to launch and run using the

    built-in VS Web Server (aka Cassini) on a random HTTP port on the machine.

    This port number can be changed if this port is already in use, or if you want to specificallytest and run using a different number:

  • 8/3/2019 ASP.net Full Details

    6/52

    Alternatively, Visual Studio can connect and debug IIS when running the web application. Touse IIS instead, select the "Use IIS Web Server" option and enter the url of the application to

    launch, connect-to, and use when F5 or Control-F5 is selected:

  • 8/3/2019 ASP.net Full Details

    7/52

    Then configure the url to this application in the above property page for the web project.

    When you hit F5 in the project, Visual Studio will then launch a browser to that webapplication and automatically attach a debugger to the web-server process to enable you todebug it.

    Note that ASP.NET Web Application Projects can also create the IIS vroot and configure theapplication for you. To do this click the "Create Virtual Directory" button.

    Click here to go to the next tutorial.

    Tutorial 2: Code-Behind with VS 2005 Web

    Application ProjectsThe below tutorial helps explain the code-behind model and project structure of pages builtwithin VS 2005 Web Application Projects. Please make sure that you have already completed

    Tutorial 1: Building Your First Web Application Project before reviewing this one.

    Some Background on the VS 2003 Code-behind Model for ASP.NET

    Applications

  • 8/3/2019 ASP.net Full Details

    8/52

    ASP.NET Pages in a VS 2003 web project have two files associated with them -- one is a.aspx file that contains the html and declarative server control markup, and the other is a .cs"code-behind" file that contains the UI logic for the page:

    Control markup declarations are defined within the .aspx file itself. For example:

    And corresponding protected field declarations are added in the .cs code-behind class that

    match the name and type of controls defined within the .aspx file. For example:

    ASP.NET does the work of wiring up a reference from this code-behind field declaration topoint to the declared control in the .aspx file at runtime. Developers can then programdirectly against this control within their code-behind file.

    VS 2003 automatically adds/updates these protected control field declarations at the top ofthe code-behind file (these are updated everytime a developer switches into WYSIWYGdesign-view):

    VS 2003 also then maintains a hidden region block inside the code-behind of tool-generatedcode to register event-handlers and keep them in sync with the design-surface:

  • 8/3/2019 ASP.net Full Details

    9/52

    There are two common complaints/problems with this:

    1) VS 2003 is adding/deleting code in the same file where the developer is authoring theirown code -- and accidental conflicts/mistakes do end up happening (for example: some codethat the developer writes can sometimes get modified or deleted by VS). The tool-generatedhidden block above is also a little "messy" for some people's tastes.

    2) The control-declarations are only updated when a developer using VS 2003 activates theWYSIWYG page designer. If a developer is only using the source-editor to customize the

    page, they will not get control updates, and will instead have to add these control declarationsmanually (which is a pain).

    VS 2005 Code-behind Model for ASP.NET Applications

    VS 2005 uses a code-behind model conceptually the same as VS 2003. Specifically, each.aspx page continues to inherit from a code-behind class that contains protected control fieldreferences for each control in the .aspx page:

    What is different between VS 2003 and VS 2005 is that Visual Studio no longer injects itstool-specific wire-up code in the developer's code-behind file. Instead, it takes advantage ofa new language feature in C# and VB called "partial types" (or partial classes) to split thecode-behind implementation across two files. One of these partial class files is thedeveloper-owned code-behind file that contains developer-written event-handlers and codefor the page. The other partial class file is then a tool-generated/maintained file that containsthe protected control field declarations and the other design-time code that Visual Studio

  • 8/3/2019 ASP.net Full Details

    10/52

    requires. The benefit of splitting them out into two separate files at design-time is that itensures that the code that VS creates and maintains never interferes (or deletes) code that adeveloper writes. At compile-time, these files are compiled together and generate a singlecode-behind class.

    With the VS 2005 Web Application project model, the design-time partial class is generated

    and persisted on disk by VS 2005. This new design-time partial-class file has the filenamenaming pattern: PageName.aspx.designer.cs. If you expand any new page created withinyour VS 2005 Web Application project, you can see this file listed under the associatedPage.aspx file along with the developer-owned code-behind file:

    If you open up the code-behind file of the page (Default.aspx.cs), you'll then see the code-behind logic of the page -- which contains all of the code and event handlers that a developerwrites (and no tool-generated "code-spit" content -- which means it stays very clean):

  • 8/3/2019 ASP.net Full Details

    11/52

    If you open the Default.aspx.designer.cs file, you'll then see the design-time code of the page-- which contains the field declarations for controls within the .aspx page:

    Because the MyWebProject._Default class is marked as "partial" in both of the above twofiles, the compiler will merge them into a single generated class at compile-time. This meansthat any variable, method or field generated in the default.aspx.designer.cs file can be usedfrom the default.aspx.cs code-behind file (just as if it was declared in the code-behind fileitself). For example, within the Page_Load event handler we could easily add the below codethat uses the "Label1" and "Calendar1" control:

  • 8/3/2019 ASP.net Full Details

    12/52

    This will compile clean and run just fine -- because the "Label1" and "Calendar1" fieldreferences have been defined within the default.aspx.designer.cs file.

    When you do a build inside a VS 2005 Web Application project, all pages, user-controls,master pages (and their associated code-behind files+design-time generated files), along withall other standalone classes within the project are compiled into a single assembly. This is thesame behavior as with VS 2003.

    Tutorial 3: Building Pages with VS 2005

    Web Application Projects

    The below tutorial demonstrates how to build ASP.NET Pages within VS 2005 WebApplication Projects. Please make sure that you have already completed Tutorial 2:Understanding Code-Behind with VS 2005 Web Application Projects before reviewing thisone.

    Coding against controls in our Default.aspx page

    In the first Hello World Tutorial we edited the Default.aspx page that is added automaticallywhen we create a new VS 2005 Web Application project.

  • 8/3/2019 ASP.net Full Details

    13/52

    Specifically we added an and control to the page:

    You can then program against these controls using your event-handlers within the code-behind file. For example:

  • 8/3/2019 ASP.net Full Details

    14/52

  • 8/3/2019 ASP.net Full Details

    15/52

    You can then set a breakpoint (press the F9 key on the line to set it on), and then hit F5 to

    compile, run and debug the page:

    Handling server events from controls in our .aspx page

    To handle a server event from a control on your page, you can either manually add an event-handler to the control yourself (by overridng the OnInit method in your code-behind class andadding the event delegate there), or by using the WYSIWYG designer to generate an eventhandler.

  • 8/3/2019 ASP.net Full Details

    16/52

    To use the WYSIWYG designer, click on the "design" tab of the .aspx page to bring up thedesign-surface. If you want to add the "default" event for the control, you can simply double-click on the control to generate an event handler for it (this is useful for things like buttons,etc). Alternatively, you can select the control on the design-surface and click on the "events"

    tab of the property-grid. This will then list the events that are available to handle:

    You can double-click on any of the events to automatically add a default named eventhandler. Alternatively, you can type the name of the event handler you wish to generate.

    You can then add whatever code you want within the code-behind file:

  • 8/3/2019 ASP.net Full Details

    17/52

    Press F5 (or Ctrl-F5) to build and run the project. Now, when a user selects a date in thecalendar, the selected date will be output using the Label control:

    utorial 4: Data Binding against Objects

  • 8/3/2019 ASP.net Full Details

    18/52

    The below tutorial demonstrates how to build ASP.NET Pages that databind against Objectswithin VS 2005 Web Application Projects. Please make sure that you have already completedTutorial 3: Building Pages with VS 2005 Web Application Projects before reviewing thisone.

    Adding Classes to the Web Project

    In this sample we'll be data-binding a GridView control on a page to a set of classes in ourweb application project.

    To begin, right-click on the project and select Add->Add New Item to add a new class called"Author" to the project:

    Note that classes can be added into any directory of the web project. There is no requirementthat they live under the /app_code directory.

    Make the new Author class public and then add some properties and constructors to it:

  • 8/3/2019 ASP.net Full Details

    19/52

    Then add a new class file called "Publisher.cs" to the project and have it implement a methodcalled "GetAuthorsByState":

  • 8/3/2019 ASP.net Full Details

    20/52

    Note that the above method uses Generics (a new feature in V2.0) to return a strongly typedList collection of type "Author".

    Choose either the "Build->Build Solution" menu item or choose "Ctrl-Shift-B" to build theproject. You now have a set of classes you can use to databind against.

    Building a Data-Bound ASP.NET Page

    Right-click on the project and select Add->Add New Item to add a new ASP.NET Pagecalled "DataSample.aspx" to the project:

  • 8/3/2019 ASP.net Full Details

    21/52

    Switch to design-view on the newly created DataSample.aspx page, add a simple page title, asearch Textbox called "TextBox1", a button, and then drag/drop a GridView control from the

    "Data" section of the Toolbox:

    Select "New DataSource" from the drop-downlist in the "Common Tasks" smart-tag menu.Select "Object" as the data-source you want to bind-to. This will then bring up a wizard thatlists all classes in your project:

  • 8/3/2019 ASP.net Full Details

    22/52

    Select the "MyWebProject.Publisher" class, and then hit next. Then choose the"GetAuthorsByState" method as the method to bind against:

  • 8/3/2019 ASP.net Full Details

    23/52

    Choose to bind the "state" parameter of the "GetAuthorsByState" method to the TextBox1 onthe page (note: change the parameter source to "control" to get this listing):

  • 8/3/2019 ASP.net Full Details

    24/52

    When you click "finish" the GridView columns will be updated to reflect the publicproperties in your Author class. Choose the "Auto format" task on the GridView control tomake it look a little better:

  • 8/3/2019 ASP.net Full Details

    25/52

    To test the page, select the DataSample.aspx page in the solution explorer, right click, andthen select the "Set as Start Page" context menu item. Then hit F5 (or ctrl-f5) to build, runand debug. When you add "wa" as the state parameter you'll get a list of authors:

    Click here to go to the next tutorial.

    Tutorial 5: Using Master Pages and Site

    Navigation

    The below tutorial demonstrates how to create and use the new ASP.NET Master Pages andSite Navigation features within VS 2005 Web Application Projects. Please make sure thatyou have already completed Tutorial 4: Data Binding against Objects before reviewing thisone.

    Add a Master Page to the Web Project

    Right-click on the project and select Add->Add New Item to add a new MasterPage called"Site.Master" to the project:

  • 8/3/2019 ASP.net Full Details

    26/52

    This will then create a default master page template that you can edit either in WYSIWYGdesign-mode or in HTML source mode:

    Modify the Site.Master content to have a logo at the top, and then use a table to (or divs withCSS) to create a two column layout in the page. Place the control

  • 8/3/2019 ASP.net Full Details

    27/52

    with the ID of "MainContent" in the second column, and leave the first column for a menuwe'll add later in this tutorial.

    If you switch into WYSIWYG design mode the Site.Master will look like this:

  • 8/3/2019 ASP.net Full Details

    28/52

    Now we are ready to have pages in our site pick up and use the master-page file.

    Update Default.aspx and DataSample.aspx to use the Master Page

    Open the default.aspx page we built in an earlier tutorial, and switch to HTML source-view.To update it to use the master-page go to the top directive and add a"MasterPageFile" attribute:

    Note that VS 2005 will provide intellisense completion for both the attribute name, as well asprovide a list of all valid master-pages in the project that you can use. Select the new

    "Site.Master" file that we just created.

    Then delete the static html previously on the page, and add an control to thepage with an id of "content1". Note that VS 2005 will provide intellisense on all of the validcontentplaceholders within the Site.Master file that you can override:

  • 8/3/2019 ASP.net Full Details

    29/52

    Wrap all previous content on the page with the control:

    Click on the "design" tab to switch into WYSIWYG mode. You'll then see the default.aspxpage inside the Master Page:

  • 8/3/2019 ASP.net Full Details

    30/52

    Select the Default.aspx page in the Solution Explorer and set it as the startup page (right-clickand choose "Set as Startup Page"). Then press F5 (or ctrl-F5) to run it.

    Now repeat the above process for the DataSample.aspx page as well:

  • 8/3/2019 ASP.net Full Details

    31/52

    Add a Web.SiteMap to the Web Project

    Right-click on the project and select Add->Add New Item to add a new Site Map file called"Web.SiteMap" to the project:

  • 8/3/2019 ASP.net Full Details

    32/52

    Edit the new web.sitemap file to have the below three nodes within the site-map (a root nodefor the home page, a sub-node for the data page we built, and another sub-node for a future

    page we are going to build in the next tutorial section):

    Open the Site.Master page up again and switch to design-mode. Delete the "todo: menu"comment in the left-most column, and then drag/drop the "Treeview" control from the"navigation" section of the Toolbox in VS:

  • 8/3/2019 ASP.net Full Details

    33/52

    Select a New Datasource from the drop-down list above, and choose the "Site Map"datasource:

    This will then data-bind the Treeview against the web.sitemap file we created above. Choosethe auto-format menu item in the "common tasks" menu and format it as "simple":

  • 8/3/2019 ASP.net Full Details

    34/52

    Note how the tree-view menu shows the current web.sitemap's hierarchy at design-time.

    Press the F5 or Ctrl-F5 key to build and run the site:

  • 8/3/2019 ASP.net Full Details

    35/52

    Notice how the tree-view menu automatically highlights (by underlining - although you can

    style it however you want) the current node in the site-hierarchy as a user navigates aroundthe site.

    Tutorial 6: Creating and Using User

    Control Libraries

    The below tutorial demonstrates how to create and use separate user-control library projectswith VS 2005 Web Application Projects. Please make sure that you have already completedTutorial 5: Using Master Pages and Site Navigation before reviewing this one.

    Why Create a User-Control Library

    Adding a user-control into an existing web application project is very easy. Simply right-clickon the project and choose the "Add New Item" menu item and pick the "Web User Control"template.

    What this tutorial will cover is how you can also use VS 2005 Web Application projects tocreate re-usable libraries of user-controls that are potentially referenced and pulled-in from

  • 8/3/2019 ASP.net Full Details

    36/52

    multiple web projects. This provides additional re-use flexibility with large-scale web-projects, and with VS 2005 Web Application Projects is now easier than it was with VS 2003.

    Create a New User Control Library Project

    Select File->Add New Project to add a new project to your existing VS Solution. Name the

    new project "MyUsercontrolLibrary" and make it a VS 2005 Web Application Project:

    Create it as a peer-directory of the "MyWebProject" project we've been working on - withboth project sub-directories stored immediately below the .sln file (note: this isn't arequirement, but can make things easier to manage):

  • 8/3/2019 ASP.net Full Details

    37/52

    Delete the Default.aspx and Web.config files that are added to new projects by default, and

    then right-click and add a new user-control to the MyUserControlLibrary project (name it"samplecontrol.ascx"):

    Your solution explorer will then look like:

  • 8/3/2019 ASP.net Full Details

    38/52

    Open up the SampleControl.ascx file, and add two textbox controls, a button, and a label intothe user-control:

    Then create and add a button event-handler to the User-control code-behind file:

  • 8/3/2019 ASP.net Full Details

    39/52

    Choose Build->Build Solution or hit Ctrl-Shift-B to build the solution and verify there are noerrors. You now have a user-control library that you can update and maintain as a separate

    project. You can add any user-control files, standalone classes, master-pages, or pages in itthat you'd like.

    Consuming User Control Libraries

    There are a couple of different strategies that can be used when consuming user-controllibrary projects. Often you will have a separate solution for managing these projects, and thenmake a file-based assembly reference to them from your web-project. For this sample,though, we will simply use a project-to-project reference.

    Within your "MyWebProject" project (which is the web app), right-click on the Referencesnode and select "Add Reference". Click on the "Projects" tab and select the

    "MyUsercontrollibrary" project. This will copy and reference the assembly with all the codefor our control library.

    Then right-click on your root project node, and choose the "Add->New Folder" command.Create an empty directory called "UserControls".

  • 8/3/2019 ASP.net Full Details

    40/52

    Right-click on the "MyWebProject" project node and pull up the properties for the project.Select the "Build-Events" tab so that we can configure a pre-build event on the project:

    In the pre-build event command-line field enter this command:

  • 8/3/2019 ASP.net Full Details

    41/52

    copy $(SolutionDir)\MyUserControlLibrary\*.ascx $(ProjectDir)\UserControls\

    This will copy the .ascx files from the UserControlLibrary into the \UserControls\ sub-directory of the web-application before each build of the project. Choose Build->BuildSolution or press Ctrl-Shift-B to build the solution and the project. Notice that when you runthe above command, it will copy the .ascx files into the project's usercontrols sub-directory,

    but not add the .ascx files themselves into the project. This means that they can be easilyexcluded from source-control for the project.

    To see this in action, compare the results of the solution explorer in normal mode:

    and then when the "Show All Files" button is clicked (notice that files not part of the projectare white):

  • 8/3/2019 ASP.net Full Details

    42/52

    To use this new user-control, create a new page called "UserControlSample.aspx" in yourweb application project. Have it use the Site.Master master-page we created earlier, and thenregister and use the user-control .ascx file:

    User-controls in VS 2005 are also now supported in WYSIWYG mode. So if you click the"design" tab of the .aspx page, you will see the user-control rendered correctly (instead of thegrey-box that was displayed in WYSIWYG mode for user-controls in VS 2003):

  • 8/3/2019 ASP.net Full Details

    43/52

    Right-click on the "UserControlsSample.aspx" file in the Solution Explorer and select the"Set as Start Page" context menu-item. Then press either F5 or Ctrl-F5 to build and run the

    web-application:

  • 8/3/2019 ASP.net Full Details

    44/52

    You can now make any changes you want to the User-Control library (including adding newuser-controls and classes). The consuming web-project will then be kept up-to-date on each

    build of the solution.

    Upgrading VS 2003 Web Projects to be VS

    2005 Web Application Projects

    The below tutorial helps explain how you can now use the VS 2005 Web Application Projectto more easily migrate existing web projects in VS 2003 to VS 2005.

    Migrating from VS 2003 to VS 2005 using the Web Application Project

    There are a couple of different strategies you can take when migrating a VS 2003 Web

    Project to VS 2005. One option (which is the default with the shipping VS 2005 bits) is tomigrate the project to use the new VS 2005 Web Site project model. For more informationclickhere

    An alternative (and now much easier) approach, is to migrate a VS 2003 Web ApplicationProject to use the VS 2005 Web Application Project option instead. The VS 2005 WebApplication Project model uses the same conceptual approach as VS 2003 (project file toinclude/exclude files, and compilation to a single assembly, etc), and so doesn't require any

  • 8/3/2019 ASP.net Full Details

    45/52

    architectural changes (the only things that might impact you are deprecated API warnings --which can optionally be ignored -- and/or language changes).

    Once VS 2005 Web Application Project RC1 is installed, the default migration wizard in VS2005 is to migrate VS 2003 Web Projects to VS 2005 Web Application Projects. This modelis much less invasive and requires fewer changes.

    Please follow the below steps in exact order. If you have problems using the below steps,please post in this forum and VS team members will be able to help.

    Step 0: Install the VS 2005 Web Application Project Preview

    VS 2005 Web Application Project support is not built-into the shipping VS 2005 (although itwill be included with the SP1 release). So the first step (if you haven't done it already) is toinstall it.

    You can learn more about it and install the release candidate build from here. After installingit, please spend a few minutes following the tutorials on this site to test it out and learn the

    basics of how it works.

    Step 1: Backup Your VS 2003 Projects

    Please make sure to save a backup of your VS 2003 Web Projects and Solutions beforeattempting any of the below steps. There is the chance that you might need to roll-back to theVS 2003 solution if you run into issues, or start over from any step.

    Step 2: Copy Remote Frontpage Projects to your local machine

    If you use Frontpage Server Extensions to access your project on a remote server, you will

    need to copy it locally before migration (if your web projects run locally then you can skipthis step). VS 2005 Web Application Projects do not support accessing projects remotly viathe Frontpage Server Extensions. If you do not copy the project locally first, migration willconvert the project to a VS 2005 Web Site project instead.

    To copy the remote site locally use the VS 2003 Copy Project menu command under theproject menu. This will lauch the copy project dialog.

  • 8/3/2019 ASP.net Full Details

    46/52

    Change the destination to "http://localhost/ProjectName" and be sure to select "All projectfiles".

    After the project has been copied locally you should remove the remote one from the solutionand use "Add Existing Project" navigating to the c:\inetpub\wwwroot\VS03Web folder whereyour project was copied.

  • 8/3/2019 ASP.net Full Details

    47/52

    Make sure the project still builds in the IDE.

    Step 3: Open Your VS 2003 Web Project and Make Sure it Compiles Clean

    Before attempting to migrate anything, please make sure that you open up your existing VS2003 solution and perform a clean-re-compile of the entire solution -- and then run the

    application. Spending 2 minutes to verify everything is working before you migrate can savea lot of grief later (especially if the cause is because of a last-minute directory move, etc).

    Step 4: Temporarily remove the VS 2003 Solution from Source Control

    If your project is currently under source control, you should temporarily remove/unbind itfrom source control prior to converting it. Once converted, you can then add it back undersource control.

    Step 5: Open the solution or project in VS 2005 and perform a project

    migration

    Close the solution in VS 2003, and start VS 2005. Choose "File->Open Project" from the Filemenu, and select the .sln or .csproj file for the solution you wish to migrate. This will causethe VS 2005 Migration Wizard dialog to launch:

    Choose a location to backup the project:

  • 8/3/2019 ASP.net Full Details

    48/52

    The conversion wizard will then perform a few steps:

    1) Update the project file to be a VS 2005 MSBuild based project file

    2) Add an xhtmlcompliance section within your web.config file to enable "legacy" htmlrendering

    3) Update your web project to go directly against IIS instead of use FrontPage ServerExtensions

    4) Fixup any language changes between .NET 1.1 and .NET 2.0

  • 8/3/2019 ASP.net Full Details

    49/52

    When complete, the solution will open up within VS 2005:

    Step 6: Compiling and Running your Web Project

  • 8/3/2019 ASP.net Full Details

    50/52

    You are now ready to compile your web project. Choose "Build->Build Solution" or Ctrl-Shift-B to do this.

    The most common issue I've seen people run into at this stage are compile conflicts with newclass names introduced with V2.0. For example: ASP.NET now has a built-in menu andtreview control (as well as built-in profile, membership and rolemanagent APIs) -- so if you

    declare these types in your VS 2003 web projects today you may get an "ambiguous type"compiler error when you compile (note: the compiler lists each line and typename for you). Ifthis happens, you should update your declarations to fully qualify the TreeView/Menu/Etc.you want to use (for example: change "TreeView" to "MyCompany.MyControls.TreeView").

    You may or may not also run into some API changes when moving to V2. This site lists theknown set of breaking API or functionality changes that were made between V1.1 and V2.0.You should consult this if you run into a problem.

    Once your project is compiling clean, you should be able to run and debug in on IIS usingASP.NET 2.0.

    Step 7: Run the Web Application

    Run the application to verify that the application is working fine. Fix up any runtime issuesthat you find. This site lists the known set of breaking API or functionality changes that weremade between V1.1 and V2.0, and will be able to help if you run into any issues.

    Step 8: Convert to Partial Classes

    When you migrate your project using the above steps, none of your code-behind page code orclasses are modified. This means that the code should look (and work) just like it did in VS2003. This makes it much easier to migrate existing code to VS 2005.

    You can optionally choose to keep your code in this format. Doing so will require you tomanually update the control field declarations within your code-behind file -- but everythingelse will work just fine in VS 2005.

    Alternatively, you can update your pages/controls to use the new partial-class support in VS2005 to more cleanly organize the tool-generated code from your code-behind logic. This isdone by separating out your current code-behind files into two separate files -- one for yourcode and event handlers, and the other a .designer.cs file that contains the control fielddeclarations for the code-behind. Please review this tutorial for more details on how this newcode-behind model works.

    To migrate your code to use this new model you should follow these two steps:

    1) Make sure your web project is compiling clean without errors. You want to make sure thatall code is compiling clean without problems before attempting to update it to use partialclasses. Please test this before proceeding.

    2) Right click on the root web project node within the solution explorer and choose the"Convert to Web Application" menu item. This will then iterate through each page or usercontrol within your project and migrate all control declarations to be declared within the

  • 8/3/2019 ASP.net Full Details

    51/52

    .designer.cs file, and event handlers to be declaratively specified on the controls in the .aspxmarkup.

    You should then do a clean re-build of your web solution. This should hopefully compileclean without errors (the cases where I've seen errors are situations where you've donecustom modification of the control declarations within your code-behind class, and theupgrade wizard mishandles them). If you have any errors in your task list, you can navigate tothe appropriate page in the solution explorer and choose the "View Code" and "ViewCodeGen" context menu items to examine the code and fix any issues.

    If for some reason the .designer.cs file doesn't have a control declaration added, you canmanually declare it within the code-behind file of the page (just like you would in VS 2003).One issue we've sometimes seen reported are cases where a developer has specificallyoverriden the type of a Usercontrol declaration in a VS 2003 code-behind file (for example:MyControl1 instead of the generic UserControl base class), and the type isn't correctly

    transferred to the .designer.cs file (producing a compile error). If the correct user-control typedeclaration isn't added to the .designer.cs file, you can optionally just delete it from the.designer.cs and add it the code-behind file of the page instead. VS 2005 will then avoid re-adding it to the .designer.cs file (it first looks in the code-behind file for declarations beforeupdating the .designer.cs file on changes).

    Note: as an advanced option, you can also upgrade each page on a page-by-page basis (justright-click on the page and choose the "Convert to Web Application" option on it). Youmight consider doing this if you want to watch closely the changes made on each page.

  • 8/3/2019 ASP.net Full Details

    52/52