Question

i have 2 radio buttons , which are optional, so by default no radio button is selected, if the user wants he can select the radio button. But on postback i should check whether the parameter entered by the user are same as the parameters defined in the application, for security. There are other fields n the screen which are optional like textboxes, but textboxes are getting passed on httppost even when the user does not enter a value it is being passed as empty, but if user does not select radio button nothing is getting passed on postback, that field is missing in httppost. Any work around to pass default value for unselected radio button on httppost.

Was it helpful?

Solution

You could place a "default" radio button, already selected, but not visible on your site ("style: display: none;"). That's the way ASP.NET works when you use some Html helpers like @Html.CheckBox(...) for instance: it places an invisible second checkbox with the same name, but containing the false value. It assures that a value will always be posted, even if the user doesn't check it (checkboxes, radio, etc are never sent with the form if they are not checked).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top