问题
Is it possible to write 'value-less' attributes to WebControl
types?
i.e. going from
1 = var div = new WebControl(HtmlTextWriterTag.Div);
2 = ???
3 = Rendered output: <div itemscope></div>
回答1:
You can created control (E.g. SomeMicroDataWebControl) derived from WebControl and overrride method "Render". In "Render" you define how your control will look like on page. Then add this class to a page or another control.
回答2:
If you're using ASP.NET MVC take a look at my blog post:
ASP.NET MVC: Add HTML5 Microdata to your applications using Metadata Providers
Hope it helps!
回答3:
You can create a System.Web.UI.HtmlControls.HtmlGenericControl control and set anything you like within it.
W3C though recommends setting a data or role attributes, so you'd have <div role-scope='item'></div>
来源:https://stackoverflow.com/questions/6495369/writing-microdata-programmatically-c-asp-net