根据单选按钮选择进行TextBox过滤

时间:2012-11-07 08:51:22

标签: c# javascript asp.net

我有RadioButtonListTextBox。 Accordindg对RadioButtonList的选择,我想过滤文本框。

 <asp:RadioButtonList ID="RadioButtonList1"  runat="server"  AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
      <asp:ListItem Text="NUMBER" Value="1" Selected="True"></asp:ListItem>
      <asp:ListItem Text="TEXT" Value="2"></asp:ListItem>
</asp:RadioButtonList>

 <asp:TextBox ID="txtID" runat="server">

当我点击值为1的listitem时,用户可以输入数字到文本框。值2,数字+文字。 我也想设定长度。有人能告诉我怎么做吗?

1 个答案:

答案 0 :(得分:0)

编写一个Javascript函数,该函数将从RadioButtonList1控件中获取选定值,并与值12进行比较。如果是1,则应允许用户仅输入数字。这可以通过文本框的客户端按键事件强制执行,该事件将检查比较结果,以允许按下的键在文本框中实际呈现。

请参阅this,了解如何使用RadioButtonList

Javascript控制中获取所选值
相关问题