The CheckBox is dead. Long live the CheckBox!Add to My Brief

Guy MacArthur | 13/07/2009

One of the most hated dreaded slightly annoying controls featured in the asp.net arsenal is the CheckBox. Microsoft, for some reason unbeknownst to me, decided we don’t need our CheckBoxes to have value. Luckily, there is a quick and lazy way of giving value back to your CheckBox.

Actually, there are many ways of doing it, and one of those ways is very proper in implementation and design… the following is not that way. Again, this is quick and for lack of a better word, lazy.

WebControls have an Attribute property which is a “collection of arbitrary attributes of that control (for rendering only) that do not correspond to properties on that control”. That’s a lot of words to say you can put stuff in the tag that the control doesn’t already have dibs on. For instance:

<asp:CheckBox id=myCheckbox value="I have value!" Text="Tick me" runat="server"></asp:CheckBox>

Perfectly valid, and though “value” isn’t a property of the CheckBox control, it is an attribute that we can access with our code like so:

string value = myCheckbox.Attributes["value"];

And tada, the CheckBox now has value! Okay, go forth and code.

The end.

tags: ProgrammingIssuesWeb DevelopmentTips & Tricks

Interested in learning more?

Wiliam is a leading supplier of web solutions and can provide expert advice to assist your business or organisation online.

Make enquiry   Request quotation

Comments

Share this page

Print this page Email this page to a friend Bookmark and Share

No Brief added yet.

My Brief results-driven approach emphasises a commitment to our clients needs through strategic analysis and best-practice.

Add to My Brief

Click on this icon to save item into My Brief. Retrieve, email and print

Drag & Drop

Drag & drop any iten with this icon into My Brief. Retrieve, email and print

Search Blogs