Home   Preview the Book   Chapter 15, TOC   Part 9

  Previous: Localizing a Web Page Design
  Next: Incorporating Bound Data into a Web Page

Modifying the Structure of a Web Page in Code

The VB Snippets application does not require a visitor to log in to view the information available. Instead, the application invites the visitor to register and log in to receive personalized information. For example, the registered visitor can identify keywords of interest and request email notifications when code snippets associated with those keywords are added to the database. VB Snippets also keeps track of the last visit by a logged-in visitor and uses that information to call attention to code snippets that were added to the database since his or her last visit. Once registered with VB Snippets, the visitor can log in to the application and receive personalized displays and update preferences on his or her profile.

After a visitor logs in, however, the rectangle in the homepage that accepts login information becomes superfluous. The Web designer recognized this by providing two design versions of the homepage: index.htm and index_logged_in.htm. The VB Snippets case study shows how to modify the appearance of a page to adapt to such circumstances. Figure 15-8 shows a screenshot of a registered visitor’s log in entries on the VB Snippets homepage. Figure 15-9 shows the top portion of the homepage after the visitor completes the login procedure.

Figure 15-8. The index.aspx page provides a convenient area for a registered visitor to log in.
Chapter 16, Figure 08.

Figure 15-9. A logged-in visitor receives a personalized version of the index.aspx page.
Chapter 16, Figure 09.

The version of index.aspx received by a logged-in visitor does not display the no-longer-needed login area. It does however, greet the visitor by name and display the word new with each snippet added to the database since this visitor’s last visit. As shown later in this chapter, some of the information used to identify a logged-in visitor comes from a persistent cookie stored at the client. The visitor can remove the cookie at any time by clicking the Log Out link that appears in the breadcrumb section of the page.

The visible property of server controls comes in handy for modifying the appearance of a Web page in circumstances such as these. When the visible property is False, ASP.NET renders no HTML for the control. You can’t get anymore invisible than that! In the present example, all of the HTML for the login area is contained within a table element with a start tag originally designed as follows:

<table class="tform" cellSpacing="6" cellPadding="0" align="right" border="0">

By adding id="tblLogin" and runat="server" attributes to the tag, you convert the table to a server control. The following code then removes the table entirely for a logged in visitor:

If User.Identity.IsAuthenticated Then
    Me.tblLogin.Visible = False
End If

An authenticated visitor does not see the tblLogin element. ASP.NET generates no HTML for it in building the response.

It is just as easy to add information that appears only to logged-in visitors. Simply add an element in the proper position like so:

<span id=pLoggedIn runat="server" visible="false"></span>

If the visitor has not logged in, the element does not appear. For a logged-in visitor, though, you can display personalized information as follows:

If User.Identity.IsAuthenticated Then
    Me.pLoggedIn.Visible = True
    Me.pLoggedIn.InnerHtml = "<b>Some personalized information...<b>"
End If

The visible property gives you great flexibility in tailoring the appearance of a Web page for particular situations. Another way that Web page displays can vary is through the use of data-bound controls, as covered in Chapter 7.

  Previous: Localizing a Web Page Design
  Next: Incorporating Bound Data into a Web Page

Home   Preview the Book   Chapter 15, TOC   Part 9

Copyright © 1996 - 2017 SoftMedia Artisans, Inc. All Rights Reserved.