Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 20th, 2005, 04:22 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default Title , Meta Keyword , Meta Description dynamic

Hi All

I have one problem in my master page to set title , meta keyword , description dynamically

I have developed one part for all title , meta keyword , meta desk admin can set dynamically

I am using MS SQL and asp.net 2 in this I don’t have HtmlMeta class
help me ?

shailesh kavathiya


shailesh kavathiya
http://www.kavathiya.20m.com
__________________
Shailesh Kavathiya
===============
Good Morning SMS
 
Old August 20th, 2005, 04:47 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Here's one way to do it:

1. In your Master page, add the following tag to the <head> of the page:
Code:
  <meta name="keywords" content="" id="MyMetaTag" runat="server" />
2. In the code behind of the Master page, add the following property:
Code:
  Public Property MetaData() As String
    Get
      Return MyMetaTag.Content
    End Get
    Set(ByVal value As String)
      MyMetaTag.Content = value
    End Set
  End Property
  3. In your Content page get a strongly typed version of your master and set the MetaData property like this:
Code:
    Dim myMaster As MainMaster = CType(Me.Master, MainMaster)
Code:
    myMaster.MetaData = "Hello World"
    This code assumes the class name of your master page is MainMaster.

Now when you run this content page you'll see Hello World appear in the keywords meta tag.

You can expand this example with other meta tags or change the MetaData property to hold something other than a string, like a custom MetaData class for example.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old August 20th, 2005, 05:18 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default

hi thanks

Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;


namespace app
{
    /// <summary>
    /// Summary description for index.
    /// </summary>
    /// 

    public class index : System.Web.UI.Page
    {

string MyMetaTag;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            index myMaster=new index();
            myMaster.MetaData="hello shailesh";

        }

        public string MetaData
        {
            get
            {
                return MyMetaTag;
            }
            set
            {
                MyMetaTag=value;
            }
        }
            #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {    
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
    }
}
Code:
<%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="true" Inherits="app.index" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD runat="server">
        <title runat="server" id="titleid"></title>
        <meta name="keywords" content="" id="MyMetaTag" runat="server" />
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body>
        <form id="Form1" method="post" runat="server">
        </form>
    </body>
</HTML>
page name is index.aspx

return MyMetaTag.Content;
this is not work

Dim myMaster As MainMaster = CType(Me.Master, MainMaster)
how to write in c#

thanks






shailesh kavathiya
http://www.kavathiya.20m.com
 
Old August 20th, 2005, 05:24 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

This code is for ASP.NET 2.0 but the code you posted is using ASP.NET 1.1.

The code I posted will *not* work on 1.1 as it's using features introduced in ASP.NET 2.0.

Quote:
quote:I am using MS SQL and asp.net 2 in this I don’t have HtmlMeta class
You said you're using ASP.NET 2, but your code shows 1.1......

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old August 20th, 2005, 05:32 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default

Hi
Sorry

i dont have seen verson that why HtmlMeta class not work in my code have any solution in asp.net 1.1

Thanks & sorry


shailesh kavathiya
http://www.kavathiya.20m.com
 
Old August 20th, 2005, 05:40 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I don't think I understand you. You say you have a Master Page, yet you use ASP.NET 1.1

The HtmlMeta class is introduced in ASP.NET 2.0 as well, just like Master Pages. So, you can't use these concepts in ASP.NET 1.1

To do something like this in ASP.NET 1.1, you can added a <asp:Literal> control to your page in the head section inside a <meta> tag. Then in Code Behind you need to declare this control and then in a method set its Text property with some code.

However, you'll need to do this on every page you create because you don't have a Master page (unless all of your pages in your site inherit from a custom Page class)....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old August 20th, 2005, 05:52 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default

hi Imar

sorry you not understand me but i understnad <asp:Literal> control you have solved my problem

thanks very much

shailesh kavathiya
http://www.kavathiya.20m.com
 
Old August 20th, 2005, 07:10 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default

hi

This code work for dynamic title , keyword , description

Code:
<%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="true" Inherits="app.index" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>

        <title><%=getTitle()%></title>

        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="keyword" content==<%=getKey()%>>
        <meta name="description"  content==<%=getDesc()%>>
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body>
        <form id="Form1" method="post" runat="server">

        </form>
    </body>
</HTML>
codebehind
Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using app.Classes;


namespace app
{
    /// <summary>
    /// Summary description for index.
    /// </summary>
    /// 


    public class index : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Literal Literal1;
         

        public Home oHome=new Home();
                         
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here

            DataSet ds=oHome.getHome();

            oHome.txtTitle = ds.Tables[0].Rows[0][1].ToString(); 
            oHome.txtKeyword =ds.Tables[0].Rows[0][2].ToString();
            oHome.txtDesc=ds.Tables[0].Rows[0][3].ToString();


        }


        public string getKey()
        {
             return oHome.txtKeyword;
        }
        public string getTitle()
        {
            return oHome.txtTitle;
        }
        public string getDesc()
        {
            return oHome.txtDesc;
        }





            #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {    
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
    }
}
shailesh kavathiya
http://www.kavathiya.20m.com
 
Old August 21st, 2007, 01:10 AM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nalla Send a message via Yahoo to nalla
Default


Hi shailesh,

You can set the Page title in the page load easily like this,

Page.Title = "Home Page"

You can set meta tag details like this,

HtmlMeta htmlMetaDesc = new HtmlMeta();
htmlMetaDesc.Name = "description";
htmlMetaDesc.Content = "This is your meta description";
Page.Header.Controls.Add(htmlMetaDesc);

HtmlMeta htmlMetaKey = new HtmlMeta();
htmlMetaKey.Name = "keywords";
htmlMetaKey.Content = "shailesh, kavathiya, shailesh kavathiya";
Page.Header.Controls.Add(htmlMetaKey);

So when the page renders, you'll see the page source like this,

<meta name="description" content="This is your meta description" />
<meta name="keywords" content="shailesh, kavathiya, shailesh kavathiya" />



nalaka hewage





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using meta tags amatytfc ASP.NET 2.0 Basics 1 August 6th, 2007 05:47 PM
meta tags ferlach HTML Code Clinic 5 June 5th, 2007 04:17 PM
meta tag rajuru Beginning PHP 1 January 30th, 2005 10:27 AM
META KEYWORDS anshul HTML Code Clinic 6 September 11th, 2004 06:06 PM
Need meta tag help, please larry HTML Code Clinic 1 January 6th, 2004 08:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.