2013-06-05 183 views
0

我在單選按鈕中選擇一個選項後回發問題。 選擇「是」後,它必須回發加載下面的文本框;但是,如果選擇「否」,則不能出現文本框。單選按鈕後丟失焦點

我已經找到了解決方案,通過我的網站http://www.codeproject.com/Articles/17571/Maintain-focus-between-postbacks-in-ASP-NET-2-0-al(我添加了單選按鈕「CurrentControl is」的列表)的其他回發問題的解決方案,但由於超出我自己的原因,它似乎並不適用於單選按鈕。

正如我剛纔創建我的帳戶,我不能發佈圖片,但是當頁面回,焦點轉移到了最後一個文本框或下拉已關注名單。

.aspx的無線電按鈕:

<table class="dataentry"> 
    <tr> 
      <td class="column1"> 
       <asp:Label ID="lblPrevEmployed" runat="server" Text="Have you ever been employed by our company?"meta:resourcekey="lblPrevEmployed"></asp:Label> 
      </td> 
      <td class="column2"> 
       <asp:RadioButton ID="rdoPrevEmployed_Yes" runat="server" GroupName="PrevEmployed" AutoPostBack="True" OnCheckedChanged="rdoPrevEmployed_OnCheckedChanged" Text="Yes" meta:resourcekey="rbPrevEmployedYes" /> &nbsp; 
       <asp:RadioButton ID="rdoPrevEmployed_No" runat="server" GroupName="PrevEmployed" AutoPostBack="True" OnCheckedChanged="rdoPrevEmployed_OnCheckedChanged" Text="No" meta:resourcekey="rbPrevEmployedNo" /> 
       <asp:CustomValidator ID="cvPrevEmployed" runat="server" ErrorMessage="You must select either Yes or No." ValidationGroup="Group" OnServerValidate="cvPrevEmployed_ServerValidate" Display="Dynamic" meta:resourcekey="cvPrevEmployed"></asp:CustomValidator> 
      </td> 
    </tr> 
</table> 

回答

0

嘗試是這樣的: (我用一個單選按鈕列表,而不是單獨的單選按鈕)

一個DIV是單選按鈕列表和第二個div用於顯示與所選單選按鈕相關的描述。

此外,還會啓用通知標籤(默認情況下會禁用)通知標籤。

[HTML]

<asp:Label ID="NotifyLabel" runat="server" Text="" ForeColor="Red" Font-Bold="true"></asp:Label> 
<br /> 
<div id="SelAccTypeSelect" runat="server" style="float: left; margin-right: 20px;"> 
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"> 
    <asp:ListItem Value="0" Text="Account Type 1" /> 
    <asp:ListItem Value="1" Text="Account Type 2" /> 
</asp:RadioButtonList> 
</div> 
<div id="SelAccTypeDesc" runat="server" style="width: 920px;"></div> 

的是含有對應於單選按鈕的值可用描述的陣列。

[代碼隱藏]

private void InitializeSelAccTypeDesc() 
{ 
SelAcctDescription[0] = "<p>This account type is for users who want to do something like this.</p>"; 
SelAcctDescription[1] = "<p>This account type is for other users who want to do something like that.</p>"; 
} 

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
// get the selected account type 
AccTypeByte = Convert.ToByte(RadioButtonList1.SelectedValue.ToString()); 

     // notify the user with the value of the selected radio button 
NotifyLabel.Visible = true; 
NotifyLabel.Text = string.Format("{0} was the value selected. - ", AccTypeByte); 

// replace the html in the div with the html from the selected array element 
SelAccTypeDesc.InnerHtml = SelAcctDescription[Convert.ToInt32(AccTypeByte)]; 
} 

*注:0可能是「不」,1可能是「是」 你可以,如果周圍的NotifyLabel聲明,只顯示基於的價值添加AccTypeByte。

+0

有沒有什麼辦法可以在上下文中看到你的代碼?我覺得這可能適用於我正在做的事情,但我目前還不清楚背後的代碼是否真的在做重點。感謝您的迴應! – GeosefKerol