Firstly, I am presuming that they are using IE to view the HTML. IE is pretty cool about attributes being added to HTML elements. They treat these attributes on HTML like expando objects (you can add them dynamically in Javascript too). So an element <b id="testB"> can have an attribute kinlaniscool simply by using the following Javascript: document.all.testB.kinlaniscool="false"; It could have been defined in the HTML as <b id="testB" kinlaniscool="false"> and you would get the same results.
To do this from C#, if you are rendering out a serverside control you could simply have the following:
HtmlGenericControl b = new HtmlGenericControl("b");
b.ID="test";
...
...
b.Attributes.Add("kinlaniscool", false);
this.Page.Controls.Add(b);
The above code might add a control to the page which is a "b" tag and that will look like: <b id="testB" kinlaniscool="false">
If you wanted to do something similar in a custom server control, I might do the following:
protected override void Render(HtmlTextWriter output)
{
output.AddAttribute("kinlaniscool", "false");
output.AddAttribute("ID", "test");
output.RenderBeginTag(HtmlTextWriterTag.B);
output.Write("Yo!");
output.RenderEndTag();
}
Basically all we are doing in the above code is overriding how the control renders its data. It will render a B tag with all the correct attributes.
And that is about it.
| Related Tags |
| html elements [feed], html tag [feed], html object [feed], attribute [feed], attributes [feed], javascript [feed], c# [feed], .net [feed], c_sharp [feed], servercontrol [feed] |
| Related Wikipedia Documents |
| HTML element, C Sharp, Meta tag, Attribute, Tag soup, Dynamic HTML, Object-oriented programming, JavaScript, ECMAScript, JavaScript engine, C Sharp |
| Related Amazon Books |
| Applied .Net Attributes: View From Amazon UK/View From Amazon USA Head First Design Patterns: View From Amazon UK/View From Amazon USA Head Rush Ajax: View From Amazon UK/View From Amazon USA JavaScript: The Definitive Guide: View From Amazon UK/View From Amazon USA Programming ASP.NET 2.0 Core Reference: View From Amazon UK/View From Amazon USA Programming C#: View From Amazon UK/View From Amazon USA ASP.NET 2 for Dummies (For Dummies S.): View From Amazon UK/View From Amazon USA C#: View From Amazon UK/View From Amazon USA |
| Related Images From Flickr |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |







