繁体   English   中英

单击文本框,它应该在c#中选择单选按钮

[英]Clicked on Textbox it should select the radiobutton in c#

我有一个单选按钮列表。 在我要添加的项目中,使用一个文本框指定您自己的值。 我首先点击了该文本框单选按钮,默认情况下应该选中该按钮。

 <td style="text-align:left" class="contract_value_bg" width="50%">
            <asp:RadioButtonList ID="rblDocumentstType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="rblDocumentstType_SelectedIndexChanged" RepeatColumns="1">

                 </asp:RadioButtonList> 
             <asp:TextBox ID="txtRFP" runat="server"  AutoPostBack="true" OnTextChanged="txtRFP_TextChanged" MaxLength="120"  />
            </td>

在此处输入图片说明

如果要在RadioButtonList中单击“指定您自己的值”,是否要在文本框中设置焦点? 还是要在用户单击TextBoxRadioButtonList选择该项目?

这是前一种情况:

protected void rblDocumentstType_SelectedIndexChanged(Object sender, EventArgs e)
{
    RadioButtonList rblDocumentstType = (RadioButtonList) sender;
    if(rblDocumentstType.SelectedIndex == 1)
    {
        txtRFP.Focus();
    }
}

如果要在TextBox获得焦点的情况下选择第二个RadioButtonList项目,则应在客户端通过使用javascript(或jQuery)处理onfocus事件来做到这一点:

<asp:TextBox ID="txtRFP" runat="server" onfocus="selectSpecifyYourOwn()"  AutoPostBack="true" OnTextChanged="txtRFP_TextChanged" MaxLength="120"  />

function selectSpecifyYourOwn() {
    var rbID = '<%=rblDocumentstType.ClientID %>';
    var rb = document.getElementById(rbID);
    var items = rb.getElementsByTagName("input");
    items[1].checked = true;      
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM