asp:CheckBox has no Value attribute - Help !!!

  • Thread starter Fresh Air Rider
  • Start date
F

Fresh Air Rider

I was extremely surprised to notice that the <asp:CheckBox> control
does not appear to have a "Value" attribute like it's HTML equivalent
does.

There are many occasions when you would want the value associated with
the checkbox to be different to the Text displayed.

ie

Value = ProductID
Text = Product description

The <asp:CheckBox> will not even allow me to set it's ID attribute
dynamically

ie ID="<%#DataBinder.Eval(Container.DataItem,"ProdID")%>"

Does anyone know how to overcome this shortfall in Microsoft's .Net
system ?

I'm sure that I'm not the only one to suffer the consequencies of this
omission.

Thanks
John
 
T

Teemu Keiski

Hi,

setting ID is not designed to be bindable, because ID is very crucial part
in postback processing. ASP.NET runtime needs to make sure it can handle the
postback processing properly and name Controls uniquely, therefore ID can't
be bound (because detecting naming conflicts happen usually already at
compile time).

You can set value for CheckBox in code by setting it to Attributes
collection.

chk.Attributes("value")="some value"

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist


I was extremely surprised to notice that the <asp:CheckBox> control
does not appear to have a "Value" attribute like it's HTML equivalent
does.

There are many occasions when you would want the value associated with
the checkbox to be different to the Text displayed.

ie

Value = ProductID
Text = Product description

The <asp:CheckBox> will not even allow me to set it's ID attribute
dynamically

ie ID="<%#DataBinder.Eval(Container.DataItem,"ProdID")%>"

Does anyone know how to overcome this shortfall in Microsoft's .Net
system ?

I'm sure that I'm not the only one to suffer the consequencies of this
omission.

Thanks
John
 
F

Fresh Air Rider

Hi Teemu

Thanks for your suggestion but that's not easy to do in the web form designer.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top