1. Technology
Web Forms navigation in ASP.NET - Part 2
Setting up the startup Web Form page for an ASP.NET application under IIS, deciding which navigation technique to use in various scenarios.
 Win prizes by sharing code!
Do you have some Delphi code you want to share? Are you interested in winning a prize for your work?
Delphi Programming Quickies Contest
 Join the Discussion
"Post your views and comments to this chapter of the free Asp.Net Delphi Programming Course"
Discuss!
 Related Resources
• A Beginner's Guide to Asp.Net Programming for Delphi developers.TOC
 Elsewhere on the Web
• About HTML
• About JavaScript

Welcome to the eleventh chapter of the FREE online programming course:
A Beginner's Guide to Asp.Net Programming for Delphi developers.
Setting up the startup Web Form page for an ASP.NET application under IIS, deciding which navigation technique to use in various scenarios.

To navigate or not to navigate - take two
In the previous chapter we've discussed using several client and server-side techniques that enable an ASP.NET developer to transfer a user from one Web Form page to another.
Being able to enable a user to move from one page to another and even control user's "progress" through your web application is very important in web development. We've already addressed several navigational techniques for supporting and controlling navigation - using Server.Transfer and Response.Redirect (as well as using the <a> tags).

In this chapter, you'll learn about the following:

  • Setting up the startup page (default page) for an ASP.NET application
  • Deciding what technique to use and when to use it
  • Main (Web) Form
    Much similar to desktop applications, every ASP.NET application will have one Web Form set to be the "Main Form". In ASP.NET, "Main Form" is the form (web page) users see when they start your application. The term "start your application" in ASP.NET context means when users type the name of your web site (or virtual folder, application name) in the address bar of the browser (and hit the "Go" button, of course).
    In general, users do not (need to) know what is the (file) name of the page that should be displayed first. What this means is that, for example, to access a web application that runs the <a href="http://aspxdelphi.net">http://aspxdelphi.net</a> site, users enter the site by simply writing http://aspxdelphi.net in the address bar of their browser, yet the page that gets displayed is "DesktopDefault.aspx" - the main Web Form for this site (web application).

    "Set as start page"
    Setting a startup page for a Delphi ASP.NET project When you are designing and developing your application "inside" the Delphi IDE, you have an option to set one page to be the start up page for the project. This page gets displayed when you select "Run-Run (F9)" or "Run-Run Without Debugging" from the main IDE menu. Note that we have not discussed the difference between running a project with or without debugging - this topic will be covered in some future chapter.
    By default, this is the first page added to the project: WebForm1.aspx, if you have not changed the default name. If you have a web project with more than one form (which you would normally have), to change the startup form, point to your project in the Project Manager, right click the form you want to be the startup form and select "Set as start page" from the popup menu. When you run the application from the IDE (with or without debugging) this Web Form will be the one that gets displayed first (the one that gets launched from a web browser). Note that the same can be accomplished by opening Project Properties dialog, pointing to ASP.NET section and manually entering the name of the Web Form in the "Start Page" text box.

    Default pages in IIS
    When you deploy your web application to a web server (again, deploying ASP.NET applications will be discussed in some later chapters), IIS provides and option to set the "default page" for a web site (web application or virtual folder). Default pages allow users to request a resource by site or application name, rather than having to know the exact page name.
    If, in your ASP.NET application, a Web Form named "DesktopDefault.aspx" needs to act as the main web form, you can use Internet Services Manager to setup a list of default pages.

    Here are the steps to make "DektopDefault.aspx" the main form (default page) for a web application:

    1. Start the Internet Services Manager (inetmgr.exe)
    2. Locate and select the virtual directory for your application
    3. Right click the application name to display the context menu ald select "Properties"
    4. Select the "Documents" tab

    Internet Services Manager - Default Document List

    5. Click the "Add" button and enter "DesktopDefault.aspx"
    6. Change the order of existing items so that DesktopDefault.aspx is the first on the list.
    7. Make sure that "Enable Default Document" is checked.

    In short: if you have a Delphi ASP.NET project called "DelphiASPNETTest" and you need "WebForm1.aspx" to be the startup page for your application so that requesting "http://localhost/DelphiASPNETTest" has the same result as requesting "http://localhost/DelphiASPNETTest/WebForm1.aspx" you would need to add "WebForm1.aspx" to the list of default paged under IIS for the "DelphiASPNETTest" virtual folder.

    Using code to enforce the startup page
    Sometimes you'll need to enforce a start page to ensure that a certain page is displayed first regardless of the "default document" list. The simples way to enforce an initial page is to use the Response.Redirect navigation in the Session_Start event in Global.asax:

    procedure TGlobal.Session_Start(sender: System.Object; e: EventArgs);
    begin
      Response.Redirect('IamTheMainForm.aspx');
    end;
    

    Note: point to Project Manager, locate and double click the Global.asax file then locate the empty TGlobal.Session_Start event handler and add the code there. It's too early to discuss the role of the Global.asax file. For the moment, let's introduce Global.asax as the file that contains code for responding to application-level events raised by ASP.NET. Every new ASP.NET application you create with Delphi automatically includes this file.

    This concludes the discussion of setting the mina form for the ASP.NET application. We'll now explore one more code-based navigation technique.

    Deciding on navigation
    We've discussed several choices for navigating from one Web Form page to another, how do you select the appropriate one? Here are some general points
    • Hyperlinks (the <a> tags) are appropriate when you want the end user to control when navigation is performed, or to choose where to go.
    • To let the user decide its destination but have a control over it, use a Web Server HyperLink control whose NavigateUrl property is dynamically set. Or use the HtmlAnchor control.
    • To let the user decide its destination but provide have a control over it, use a Web Server HyperLink control whose NavigateUrl property is dynamically set. Or use the HtmlAnchor control.
    • Using Response.Redirect requires two trips to the server and imposes performance penalties and should only be used when the three following circumstances demand its use...
      1) When redirecting to a remote server.
      2) When redirecting to a different website on the same server.
      3) When redirecting to static pages, i.e. from .aspx to .htm, or to pages generated by different application servers such as .asps to .php.
    • Otherwise use the Server.Transfer method
    To the next chapter: A Beginner's Guide to ASP.NET Programming for Delphi developers
    That's it for today, in the next chapter we'll continue to explore Web Forms navigation an passing values from one Web form to another and back. Stay tuned!

    If you need any kind of help at this point, please post to the Delphi Programming Forum where all the questions are answered and beginners are treated as experts.

    A Beginner's Guide to ASP.NET Programming for Delphi developers: Next Chapter >>
    >> An introduction to ASP.NET Web Server controls

    ©2014 About.com. All rights reserved.