Dynamic Title and Meta Data on Content Page having Master Page attached.

This is the most simple way to assign Title and Meta data on content page having Master Page attached.
First add a Master Page in your .net website. The removes the title tag from the master page.
Then add new page to your website and attach the master page with removed title tags. Now in the Page Load event of content page add the following line.

Below is the simple code.


protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HtmlTitle title = new HtmlTitle();
            title.Text = "Dynamic Page";
            Header.Controls.Add(title);


            HtmlMeta tag = new HtmlMeta();
            tag.Name = "keywords";
            tag.Content = "key1, key2, key3, key4";
            Header.Controls.Add(tag);


            HtmlMeta des = new HtmlMeta();
            des.Name = "desription";
            des.Content = "This is a dynamic description allocated to the page...";
            Header.Controls.Add(des);
        }


    }


Enjoy.... :)

Comments

Post a Comment

Popular posts from this blog

Get Query String Values With Javascript

Change Css Class of li in ul onclick

Change Text Color with Javascript