我有一个问题后,张贴回来后,选择一个选项在单选按钮。选中“是”后,必须回发以加载下面的文本框;但是,如果未选中文本框,则不得显示文本框。
我在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" />
<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>发布于 2013-06-05 16:13:18
尝试这样的方法:(我使用了RadioButtonList而不是单个的RadioButtons)
一个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可以是'No‘,1可以是'Yes’,您可以在NotifyLabel周围添加一个if语句,以仅显示基于AccTypeByte的值。
https://stackoverflow.com/questions/16940805
复制相似问题