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

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:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular