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";

Comments

Popular Posts

Resolving the "n timer(s) still in the queue" Error In Angular Unit Tests

How to Get Norton Security Suite Firewall to Allow Remote Desktop Connections in Windows

Silent Renew and the "login_required" Error When Using oidc-client

Fixing the "Please add a @Pipe/@Directive/@Component annotation" Error In An Angular App After Upgrading to webpack 4

How to Determine if a Column Exists in a DataReader