2011-06-20 12 views
0

私はこのコンストラクタ持ち、こんにちはC#の

をコンストラクタで選択されたRadioButtonを決定します。

public EmployeeCategorizationControl() 
     { 


     } 

、多くのラジオボタン:私のコンストラクタで

<asp:RadioButtonList ID="selectedYesNoQuestionBlock1" runat="server" RepeatDirection="Horizontal" 
       OnSelectedIndexChanged="Question1GotAnswered" AutoPostBack="true"> 
       <asp:ListItem Text="Yes" Value="1"></asp:ListItem> 
       <asp:ListItem Text="No" Value="0"></asp:ListItem> 
      </asp:RadioButtonList> 

<asp:RadioButtonList ID="selectedYesNoQuestionBlock2" runat="server" RepeatDirection="Horizontal" 
       AutoPostBack="true" OnSelectedIndexChanged="Question2GotAnswered"> 
       <asp:ListItem Text="Yes" Value="1"></asp:ListItem> 
       <asp:ListItem Text="No" Value="0"></asp:ListItem> 
      </asp:RadioButtonList> 

を、どのように私はラジオを決定することができますボタンが選択されていますか?

ありがとうございます!

+0

[この質問](http://stackoverflow.com/questions/378620/getting-selected-value-from-radiobuttonlist)をチェックし、それが重複している可能性があり。コンストラクタでも同様のことをしたいと思うでしょう。お役に立てれば。 – lhan

答えて

2

asp.netを使用すると、コンストラクタのコントロールとやりとりすることは、page life cycleの仕組みのためには良い考えではありません。ページのライフサイクルmsdnページを見て、代わりにLoadまたはInitイベントを考慮する必要があります。

0

ページインスタンスを作成した後の後にまでRequestを使用することはできません。後でthe page lifecycleにそれをする必要があります。あなたはを通して値を直接アクセスできる上、その点から -

protected sub Page_Init(object sender, EventArgs args) { 
    var selection = Request.Form["selectedYesNoQuestionBlock1"]; 
} 

Loadがあなたのコントロールオブジェクトに要求値をマップ:あなたが唯一の要求によって選択にアクセスすることができますLoad前に(例えば、初期化中)

コントロール:

protected sub Page_Load(object sender, EventArgs args) { 
    var selection = selectedYesNoQuestionBlock1.SelectedValue; 
}