Tag Archives: asp.net

asp.net Clean up CSS output

How to get rid of all the ugly auto markup generated in ASP.net:

http://weblogs.asp.net/scottgu/archive/2010/03/30/cleaner-html-markup-with-asp-net-4-web-forms-client-ids-vs-2010-and-net-4-0-series.aspx

New ClientIDMode Property on Controls

ASP.NET 4 supports a new ClientIDMode property on the Control base class.  The ClientIDMode property indicates how controls should generate client ID values when they render.  The ClientIDMode property supports four possible values:

  • AutoID—Renders the output as in .NET 3.5 (auto-generated IDs which will still render prefixes like ctrl00 for compatibility)
  • Predictable (Default)— Trims any “ctl00” ID string and if a list/container control concatenates child ids (example: id=”ParentControl_ChildControl”)
  • Static—Hands over full ID naming control to the developer – whatever they set as the ID of the control is what is rendered (example: id=”JustMyId”)
  • Inherit—Tells the control to defer to the naming behavior mode of the parent container control

 

asp.net Masterpages and Metatags

There are a couple of ways to edit meta tags in MasterPages in asp.net (vb).

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Page.Title = String.Format(“Master Page Tutorials :: About :: {0:d}”, DateTime.Now)

‘ Programmatically add a <meta> element to the Header
Dim keywords As New HtmlMeta()
keywords.Name = “keywords”
keywords.Content = “master page,asp.net,tutorial”

Page.Header.Controls.Add(keywords)

‘ Programmatically add a <meta> element to the Header
Dim description As New HtmlMeta()
description.Name = “description”
description.Content = “This is a Sample Description”

Page.Header.Controls.Add(description)

End Sub

New way: (thanks to: http://weblogs.asp.net/scottgu/archive/2010/01/05/asp-net-4-seo-improvements-vs-2010-and-net-4-0-series.aspx)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Page.Title = String.Format(“Master Page Tutorials :: About :: {0:d}”, DateTime.Now)

Page.MetaDescription = “Hello World”
Page.MetaKeywords = “Some, keywords, that, go here”

End Sub

I prefer the output of the first type, even tho it has more code involved.