0

i have textbox in repeater and i want to validate it to accept numbers only i have code like this

<asp:Repeater ID="Repeater1"  runat="server">
             <HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>id</th>
<th align=left>Room Categories</th>
<th>single</th>
<th>Double</th>

</tr>
</HeaderTemplate>
<ItemTemplate>

<tr>
<td width="5%">
    <asp:Label ID="Label3" runat="server" Text= '<%# Container.DataItem("packageid")%>' /></td>
<td> <asp:CheckBox ID="chk_packages" AutoPostBack=true runat="server" Text = <%#Container.DataItem("package_name")%> />  </td>

<td><%#Container.DataItem("single_rate")%><asp:CheckBox  AutoPostBack=true ID="single" Enabled=false runat="server" />Number of Rooms<asp:TextBox ID="txt_single" OnTextChanged="NumberOnly();"  Enabled=false  width="10px"   MaxLength="2" runat="server"></asp:TextBox></td>

<td><%#Container.DataItem("double_rate")%><asp:CheckBox  AutoPostBack=true ID="Double" Enabled=false runat="server" />Number of Rooms<asp:TextBox ID="txt_double" Enabled =false  width="10px"   MaxLength="2" runat="server"></asp:TextBox></td>
<td></td>
</tr>


          

</ItemTemplate>

<FooterTemplate>
   
</table>
           
</FooterTemplate>

         </asp:Repeater>
<script type="text/javascript">
       function NumberOnly() {
           var t = window.event.keyCode;

           if (t >= 48 & t <= 57)
               return;
           window.event.keyCode = 0;
       } 
</script>

it gives error like this

Line 777:<td><%#Container.DataItem("single_rate")%><asp:CheckBox AutoPostBack=true ID="single" Enabled=false runat="server" />Number of Rooms<asp:TextBox ID="txt_single" OnTextChanged="NumberOnly();" Enabled=false width="10px" MaxLength="2" runat="server"></asp:TextBox></td>
Line 778:
Line 779:<td><%#Container.DataItem("double_rate")%><asp:CheckBox AutoPostBack=true ID="Double" Enabled=false runat="server" />Number of Rooms<asp:TextBox ID="txt_double" Enabled =false width="10px" MaxLength="2" runat="server"></asp:TextBox></td>

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by croker10
0

erum,

You can use a FilteredTextBoxExtender for this.

It is part of the AJAX toolkit that is used in asp.net. You should be able to add AjaxControlToolkit to your project references.

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" TargetControlID="Number_TextBox" FilterMode="ValidChars" ValidChars="0123456789" runat="server" />

This will force the textbox to only accept numbers. Hope that helps. If you have any questions, check out http://www.asp.net/ajax

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.