In this article I will explain how to add Meta tags dynamically to aspx page in asp.net.
In Previous posts I explained Differences between appsettings and connection strings, jQuery get hidden field values from asp.net gridview and many articles regarding Asp.net, Gridview, SQL Server, Ajax, JavaScript etc. Now I will explain how to add Meta tags dynamically to aspx pages in asp.net.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Add meta tags dynamically to aspx page in asp.net</title>
<meta name="description" content="Aspdotnet-Suresh offers Asp.net,C#.net,SQL
Server,Web Services,Ajax,JavaScript,JQuery,Gridview articles and
examples" />
<meta name="keywords" content="asp.net,C#.NET,suresh
dasari,GridView,DropDownList,,JavaScript,JQuery,XML" />
</head>
<body>
<form id="form1"
runat="server">
<div>
<b>Aspdotnet-Suresh.com Meta Tags Example</b>
</div>
</form>
</body>
</html>
|
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<form id="form1"
runat="server">
<div>
<b>Aspdotnet-Suresh.com Meta Tags Example</b>
</div>
</form>
</body>
</html>
|
using System;
using System.Web.UI.HtmlControls;
|
protected void
Page_Load(object sender, EventArgs e)
{
// set page title
Page.Title = "Add
meta tags dynamically to aspx page in asp.net";
//Page description
HtmlMeta pagedesc = new
HtmlMeta();
pagedesc.Name = "Description";
pagedesc.Content =
"Aspdotnet-Suresh offers
Asp.net,C#.net,SQL Server,Web Services,Ajax,JavaScript,JQuery,Gridview
articles and examples";
Header.Controls.Add(pagedesc);
//page keywords
HtmlMeta pagekeywords = new
HtmlMeta();
pagekeywords.Name = "keywords";
pagekeywords.Content = "asp.net,C#.NET,suresh
dasari,GridView,DropDownList,,JavaScript,JQuery,XML";
Header.Controls.Add(pagekeywords);
}
|
Partial Class
VBSample
Inherits System.Web.UI.Page
Protected Sub
Page_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Load
' set page title
Page.Title = "Add
meta tags dynamically to aspx page in asp.net"
'Page description
Dim pagedesc As New HtmlMeta()
pagedesc.Name = "Description"
pagedesc.Content = "Aspdotnet-Suresh
offers Asp.net,C#.net,SQL Server,Web Services,Ajax,JavaScript,JQuery,Gridview
articles and examples"
Header.Controls.Add(pagedesc)
'page keywords
Dim pagekeywords As New HtmlMeta()
pagekeywords.Name = "keywords"
pagekeywords.Content = "asp.net,C#.NET,suresh
dasari,GridView,DropDownList,,JavaScript,JQuery,XML"
Header.Controls.Add(pagekeywords)
End Sub
End Class
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|

Subscribe by RSS
Subscribe by Email
5 comments :
thanks suresh it really nice .. then what use we i add meta data dynamically ... i'm new for asp.net pls ..
suresh. this is awesome
Thanks for the post. I had been looking for something related and found your web site in the process.. I will definitely be back for more.
Hello Suresh
I'm Deepika , Actually I tried this code ,the problem with this is always title only getting displayed but not metadata . I'm unable to understand where I went wrong ,so, if possible can u help me in this context ?
thank you friend