Radio button loses value in postback

Hi I have a set of radio buttons for yes and no that have name = select. Yes is checked by default. They are both runat = "server". I read the postback selection as shown below. It works fine until the check is interrupted. For example, if I chose no and the check failed during the postback, I still see no. But if I submit the form after fixing everything, the value will be considered “yes” on the server side! This is a bug in .net, and if so, how to fix it?

foreach (string key in Request.Form.AllKeys)
{
    if (key.EndsWith("choice"))
        return Request.Form[key] == "yes";
}
+3
source share
2 answers

, viewstate .

0

DataBinding RadioButton Controls, , PostBacks :

if (!IsPostBack)
     YourControlId.DataBind();
0

Source: https://habr.com/ru/post/1743849/


All Articles