AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=558&pId=-1
CodeSnip: Setting Commonly-Used Tags Programmatically
page
by Steven Swafford
Feedback
Average Rating: 
Views (Total / Last 10 Days): 12263/ 28

The following code shows how to programmatically set meta content tag that instructs the client to wait ten seconds and then to go to the specified URL.  Also, it will render the stylesheet tag attribute in this same method.

<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
    aspNet.Attributes("content") = "10;URL="
    StyleSheet.Attributes["href"] = "style.css"
End Sub
</script>

<html>
<meta id="aspNet" runat="server" http-equiv="refresh"></meta>
<link id="StyleSheet" rel="stylesheet" type="text/css" runat="server"></link>
<body>
Content
</body>
</html>

<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
    aspNet.Attributes["content"] = @"10;URL=";
    StyleSheet.Attributes["href"] = "style.css";
}
</script>

<html>
<meta id="aspNet" runat="server" http-equiv="refresh"></meta>
<link id="StyleSheet" rel="stylesheet" type="text/css" runat="server"></link>
<body>
Content
</body>
</html>

The resulting HTML tags are shown below.

<meta id="aspNet" http-equiv="refresh" content="4;URL="></meta>
<link id="StyleSheet" rel="stylesheet" type="text/css" runat="server" href="style.css"></link>

Notice the very important presence of the closing tag in the instance of the meta tag and stylesheet link tags.

You could even extend this functionality even further by creating and compiling a utility class that has all your common code such as page attributes, email addresses, and etc. This way, when a change is required, this one single class is the only piece of the application that will require changes in the case of changing an email address and any page stylesheet references as I used in my example above. This snippet should, however, give you an idea on how to consolidate common tags and attributes used within an application.



©Copyright 1998-2018 ASPAlliance.com  |  Page Processed at 2018-10-21 6:20:50 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search