When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
Print this page.
Published: Saturday, May 15, 1999

Creating a Customized Homepage
By Christopher Miller

Cookies Problem: Some folks have reported problems saving/reading cookies with this article's code examples. There is a "fix" or "workaround" that might work for you.... Read More...

One of the best ways to make your visitors feel like they are part of an Online "community" and to add interactivity to your site, is to offer them a way to create custom homepages. Often called a "portal", this homepage will be your visitor's gateway to the internet and contain their favorite colors, links, email addresses, and much more. If you have a commerce site, You can take this concept a step further and add targeted marketing information based on a survey you have your visitors fill out. The possibilities are endless.

- continued -

In this example, we will create this homepage by setting a series of cookies that contain the customized information. We will gather this information through a form that the visitor is sent to after clicking on an "edit" button.

The working example of this code can be found at the following address.


Lets start by creating two pages, my_homepage.asp and edit.asp. The first page will be the page that is getting the customization, and the second page is where we collect the data.

You need to then decide what information you want the user to be able to edit and customize. In this example, the user is able to edit the following items:

  • Name
  • Email
  • Background Color
  • Table Background Color
  • Text Color
  • Link Color
  • Visited Link Color
  • Favorite Places
  • Address Book

We then need to create a simple HTML form on the edit page to collect the values to be passed to the cookies (I am assuming you know how to do this already). To collect the data, simply write the contents of the form field to the cookie (For more information about cookies, read "Cookie Monster: Using Cookies in ASP", by Ian Stallings):

Response.Cookies("CookieName") = Request.Form("FieldName")
Response.Cookies("CookieName").Expires = "Jan 1, 2000"

There are two ways of collecting the data from the form, we can write each cookie individually (as show above), or we can use a for...each method:

For Each Item In Request.Form

Response.Cookies(Item) = Request.Form(Item)
Response.Cookies(Item).Expires = "Jan 1, 2000"

The for...each method will save you a lot of time and effort. Keep in mind however, the cookie name will correspond with the form input name which you will need to remember for the my_homepage file.

Now that we have a method of collecting all of the values, we need to create the customized home page.

Lets start by using the Option Explicit function. By using option explicit, you are forced to declare all of the variables you are going to use in your application. This is handy trick to avoid misspellings. We will then declare our variables:

Dim myName, myBGColor, myTableColor, myTextColor
Dim myLinkColor, myVlinkColor
Dim myLinks, myEmails
Dim objMail, MessageBody

The next step is to check for cookies and set all of the values for the variables. You can use a default value if there is no cookie set.

IF Request.Cookies("cookieName") = "" THEN

myName = "My "
myName = Request.Cookies("cookieName") & "'s "

IF request.Cookies("cookieBGColor") = "" THEN

myBGColor = "#FFFFFF"
myBGColor = Request.Cookies("cookieBGColor")

IF Request.Cookies("cookieTableBGColor") = "" THEN

myTableBGColor = "#9BA3CD"
myTableBGColor = Request.Cookies("cookieTableBGColor")

IF Request.Cookies("cookieTextColor") = "" THEN

myTextColor = "#000000"
myTextColor = Request.Cookies("cookieTextColor")

IF Request.Cookies("cookieLinkColor") = "" THEN

myLinkColor = "blue"
myLinkColor = Request.Cookies("cookieLinkColor")

IF Request.Cookies("cookieVLinkColor") = "" THEN

myVLinkColor = "purple"
myVLinkColor = Request.Cookies("cookieVLinkColor")

You then need to set up the links to be clickable:

myLinks = "<a href='" & Request.Cookies("cookieLinkOne") & "'>" & Request.Cookies("cookieLinkOne") & "</a><br>"

I use a simple Response.Redirect to send the user to the edit.asp page if the edit button is clicked.

IF Request.Form("cmdEdit") = "Edit" THEN


In the body of the page, you want to use the values you define earlier for the customization. Below is an example of what the body of the page looks like:

<body bgcolor="<%Response.Write(myBGColor)%>" text="<%Response.Write(myTextColor)%>" link="<%Response.Write(myLinkColor)%>" vlink="<%Response.Write(myVLinkColor)%>">

To make the page a little more interactive, I have set up a Email form using the addresses set by the user in a drop-down menu for the To field. I used a simple CDONTS script to accomplish this:

IF Request.Form("cmdSend") = "Send" THEN

Set myMail = CreateObject("CDONTS.Newmail")
myMail.From = Request.Form("From")
myMail.To = Request.Form("To")
myMail.Subject = Request.Form("Subject")
myMail.Body = Request.Form("Message") myMail.Send


It is as simple at that. Keep in mind, the code and example I have provided have no error checking, so you will want to add your own handlers. You may also want to pass the values of the cookies into session variables to be used throughout the site, rather that just on the single page. Enjoy :o}

Cookies Problem: Some folks have reported problems saving/reading cookies with this article's code examples. There is a "fix" or "workaround" that might work for you.... Read More...


  • ASP Code for Customizable Homepage
  • ASP Code for the Edit Page

    Christopher Miller

  • ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article