Click here to Skip to main content
14,739,787 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is the code inside gridview and am dynamically generating row on Add button .

                                        <asp:TextBox ID="txtweight_fact" runat="server" Height="41px" Width="42px"

                                            OnKeyPress="return isNumberKey(this,event);"  text="0.00"

                                            MaxLength="4" ></asp:TextBox>
                                        <br />
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" Display="Dynamic"

                                            ControlToValidate="txtweight_fact" ErrorMessage="*" ValidationGroup="valgrp_func"></asp:RequiredFieldValidator>


The Code for add button
                                           <asp:Button ID="BtnAdd" runat="server" OnClick="ButtonAdd_Click" ValidationGroup="valgrp_func"

                                Text="Add" /></center>

I want to validate the textbox with Id "txtweight_fact" but not able to validate using the client ID .
Please suggest solution.

Adapt from this example:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head id="Head1" runat="server">
<script  type="text/javascript">
    function validateNumberRange(sender) {
        var e = sender;
        var textboxVal = e.value;
        if (textboxVal >= 0.00 && textboxVal <= 1.00) {
            return true;
            alert('Please enter a number between 0.00 to 1.00');
        return false;
    <form id="form1" runat="server">

    <asp:GridView ID="GridView1" runat="server">
            <asp:TemplateField HeaderText="Text Box Column">
                    <asp:TextBox ID="textbox1" runat="server" onkeyup="return validateNumberRange(this);"/>

Ni!E$H_WAGH 21-Feb-14 0:58am
Thank you Very much Sir .
Happy Programming...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900