C#およびASP.NET 4.0のソリューションに取り組んでいます。データベース情報に基づいて動的に作成された、ページからラジオボタンの値を取得しようとしています。
ページソースで生成されるものは次のとおりです。
<td>
  <input id="masterMain_3Answer_0" type="radio" name="ctl00$masterMain$3Answer"     
    value="Y" onclick="return answeredyes(3);" />
  <label for="masterMain_3Answer_0">Y</label>
</td>
<td>
  <input id="masterMain_3Answer_1" type="radio" name="ctl00$masterMain$3Answer" 
    value="N" onclick="return answeredno(3,'desc');" />
  <label for="masterMain_3Answer_1">N</label>
</td>
送信ボタンのOnClick機能内で、ユーザーの入力に基づいてYまたはNが選択されているかどうかを収集します。
これが私がこれまでに書いたものです:
      RadioButton _rbAnswer = new RadioButton();
      RadioButtonList _rbList = new RadioButtonList();
     ContentPlaceHolder cp = (ContentPlaceHolder)Master.FindControl("masterMain");
     _rbAnswer = (RadioButton)Master.FindControl("masterMain_3Answer_0");
     HtmlInputRadioButton rb = (HtmlInputRadioButton)Master.FindControl("masterMain_3Answer_0");
     _rbAnswer = (RadioButton)cp.FindControl("masterMain_3Answer_0");
     _rbList = (RadioButtonList)cp.FindControl("masterMain_3Answer_0");
問題なくContentPlaceHolderを取得できますが、取得を試みた後、残りのオブジェクトはnullになります。また、「masterMain_」を削除しようとしましたが、それでもコントロールを見つけたくありません。
個々のラジオボタンリストが追加されたコードは次のとおりです
                TableRow _tempRow = new TableRow();
                TableCell _cellOK = new TableCell();
                 RadioButtonList _rbList = new RadioButtonList();
                _rbList.ID = r[0].ToString()+"Answer";
                _rbList.RepeatDirection = RepeatDirection.Horizontal;
                //add options for yes or no
                 ListItem _liOk = new ListItem();
                _liOk.Value = "Y";
                 ListItem _linotOk = new ListItem();
                _linotOk.Value = "N";
                _rbList.Items.Add(_linotOk);
                //add cell to row
                _rbList.Items.Add(_liOk);
                _cellOK.Controls.Add(_rbList);
                _tempRow.Cells.Add(_cellOK);
                 //add the row to the table
                 stdtable.Rows.Add(_tempRow);