2013-06-05 136 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