Sponsored Ad

Wednesday, July 7, 2010

How to change HTML Meta tags using HtmlGenericControl in C#

This example wil help you to define your own meta tags using c#. just define a meta tag me ASPX page and assign values ( name and contents ) in C# file.

Like this line added in aspx page for description meta tag.

<meta id="MetaDescription" runat="server" />

And corresponding line added in C# which assign the values.

MetaDescription.Attributes["Name"] = "Description";

MetaDescription.Attributes["CONTENT"] = "Webpage meta description";

Now you can check the viewsource of the page to check the description meta tag.

<meta id="MetaDescription" Name="Description" CONTENT="Webpage meta description"></meta>

Webpage view source:

How to change HTML Meta tags using HtmlGenericControl in C#

How to change HTML Meta tags using HtmlGenericControl in C#

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        MetaDescription.Attributes["Name"] = "Description";
        MetaDescription.Attributes["CONTENT"] = "Webpage meta description";

        MetaKeyword.Attributes["Name"] = "Keyword";
        MetaKeyword.Attributes["CONTENT"] = "Webpage Meta Keywords";

    }
</script>

<html xmlns="">
<head>
    <title>Use of HtmlGenericControl class</title>
    <meta id="MetaDescription" runat="server" />
    <meta id="MetaKeyword" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <h1>
                How to change HTML Meta tags using HtmlGenericControl.</h1>
        </div>
    </form>
</body>
</html>

No comments:

Post a Comment

Sponsored Ad

Development Updates