How To Set The Value Attribute Of An ASP.NET RadioButton In Server-Side Code
Recently I ran into a situation wherein I needed to set the value attribute of a radio button rendered via an ASP.NET RadioButton control -- except I found there was no Value property. I attempted to set it via the InputAttributes property of the control, but this didn't work either -- if I set it using the value key, my value would be ignored and replaced with the server-side ID of the control (which is what ASP.NET uses as the value attribute by default), and if I added a value attribute this way, it would add an additional value attribute, giving me two in the same control.
The solution was actually a simpler approach: merely setting the value using the control's Attributes property (not InputAttributes). Here's an example:
rdoButton.Attributes["value"] = "somevalue";
The solution was actually a simpler approach: merely setting the value using the control's Attributes property (not InputAttributes). Here's an example:
rdoButton.Attributes["value"] = "somevalue";
Comments
Post a Comment