Forum Moderators: open
The site uses the inherit function to call the master file and due to the fact the site is precompiled this makes the task a little more difficult.
I thought the tutorial on this page might help [codeproject.com...]
but I hit a dead end when my site returned an error because you can't use the App_Code folder on a precompiled site.
My ASP is fairly basic so if you can give me any help with this it would be hugely appreciated.
To achieve this you will need to have access to the source code of your compiled web application.
If you have this you can add the new BasePage class anywhere in your solution (the App_Code folder is only necessary when you have a Web Site instead of a Web Application). After adding the BasePage class you can then allow all of your pages to inherit from this.
Hopefully this helps you out, if I have misunderstood let me know.
It could look something along these lines.
<script runat="server" Language="C#">
System.Web.UI.HtmlControls.HtmlGenericControl Meta;
string Keywords = string.Empty;
string Description = string.Empty;
//----------------------------------------------------------
//Logic to retrieve the proper Keywords and Description go here.
//----------------------------------------------------------
//Fill in the proper coding here. (Most likely DB Calls.)
//----------------------------------------------------------
//Add Meta Controls to the Header.
//----------------------------------------------------------
if (Keywords!=string.Empty)
{
Meta = new HtmlGenericControl("meta");
Meta.Attributes.Add("content", Keywords);
Meta.Attributes.Add("name", "KEYWORDS");
this.Page.Header.Controls.Add(Meta);
}
if (Description!=string.Empty)
{
Meta = new HtmlGenericControl("meta");
Meta.Attributes.Add("content", Description);
Meta.Attributes.Add("name", "DESCRIPTION");
this.Page.Header.Controls.Add(Meta);
}
</script>
[edited by: Ocean10000 at 1:21 am (utc) on July 9, 2009]
The master file on my site hasn't been precompiled (as far as I can tell) and I was wondering if you could give some further clarification how I might control the meta tags from within the individual pages. The precompiled sections on this particular site seem to be seperate from the graphical interface as I can still edit this for all pages. I want to be able to control the meta tags from within each individual page using variables within the code. I would be happy to do this via the master file if it's not possible via each seperate page.
I'm more of a PHP coder which is why I'm a bit slow with the basics.
The master file on my site hasn't been precompiled
Could you post the code you have available for the MasterPage and for one of the content pages? (edit out the particulars if you can, we don't need the html markup)
<%@ master language="C#" autoeventwireup="true" inherits="DDMaster, App_Web_ddmaster.master.cdcab7d2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>{snipped}</title>
<meta name="keywords" content="{snipped}" />
<meta name="description" content="{snipped}" />
<link href="App_Themes/Default/Default.css" rel="stylesheet" type="text/css" />
<link href="App_Themes/Default/print.css" rel="stylesheet" media="print" type="text/css" />
<link href="favicon.ico" rel="Shortcut Icon" />
<script type="text/javascript" src="{snipped}"></script>
</head> and here is the lettings page;
<%@ page language="C#" masterpagefile="~/DDMaster.master" autoeventwireup="true" inherits="Lettings, App_Web_lettings.aspx.cdcab7d2" title="{snipped}" %><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
{snipped}
</asp:Content>
//----------------------------------------------------------
//Makes sure there is a Header Defined with runat="server"
//And will skip it if it is not defined.
//----------------------------------------------------------
if (this.Page.Header!=null)
{
//----------------------------------------------------------
//Logic to retrieve the proper Keywords and Description go here.
//----------------------------------------------------------
Keywords = "Some,Keywords";
Description= "Description";
Title = "Title Goes Here";
//----------------------------------------------------------
//Simply Adds a Title.
//----------------------------------------------------------
if (Title!=string.Empty)
{
Page.Header.Title = Title;
}
//----------------------------------------------------------
//Add Meta Controls to the Header.
//----------------------------------------------------------
if (Keywords!=string.Empty)
{
Meta = new HtmlGenericControl("meta");
Meta.Attributes.Add("content", Keywords);
Meta.Attributes.Add("name", "KEYWORDS");
this.Page.Header.Controls.Add(Meta);
}
if (Description!=string.Empty)
{
Meta = new HtmlGenericControl("meta");
Meta.Attributes.Add("content", Description);
Meta.Attributes.Add("name", "DESCRIPTION");
this.Page.Header.Controls.Add(Meta);
}
}
}
</script>