Show a Footer for All ASP .NET Pages in a Site

This tip is useful for displaying a uniform footer in all your site’s pages, including any pages served from the site’s subdirectories.

In this case, assume you want to display a footer message with each and every request under any subfolder of the site. Consider how shared web-hosting companies display footer banner ads on every web page they serve by automatically appending the banner ad to every page. Note that their developers don’t have to write or include any code for that to happen. You want to give your application the exact same capability. Here’s the process.

First, add a new Global Application Class (Global.asax) to your application. When you open that file, if you’re using Visual Studio, you’ll find that the IDE generates commonly used Application and Session event handlers for you. However, the automatically generated event handlers aren’t suitable for adding a footer. Application_Start and Application_End won’t work, because you want the footer to show on each and every request, not only when the application is starting or ending. Application_Error is obviously to tap into unhandled exceptions at the page level, so that’s not appropriate either.

Instead, you need to add an event handler that Visual Studio doesn’t insert automatically Application_EndRequest.

First, here’s the code:

Sub Application_EndRequest(ByVal sender As Object, ByVal e As EventArgs)    With Response     .Write(String.Format("
", _ Unit.Percentage(100), "text-align:center;")) .Write(String.Format("{1}", _ "footer2.jpg", "Footer")) .Write("
") End With End Sub

Application_EndRequest, as the name suggests, is the last event where you have an opportunity to modify what ASP.NET is sending to the client.

The code adds an image tag and sets its source (src) property to the name of the image to display.

There are other ways to achieve similar functionality, such as using Master Pages or creating a base page class that includes the footer, and inheriting all pages from that; however, this method works even with existing sites.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS