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 .


<ItemTemplate>
                                        <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>

                                    </ItemTemplate>

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

                                Text="Add" /></center>
                                    </FooterTemplate>



I want to validate the textbox with Id "txtweight_fact" but not able to validate using the client ID .
Please suggest solution.
Regards
Ni!E$#UPDATED
Posted

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script  type="text/javascript">
    function validateNumberRange(sender) {
        var e = sender;
        var textboxVal = e.value;
        if (textboxVal >= 0.00 && textboxVal <= 1.00) {
            return true;
        }
        else
            alert('Please enter a number between 0.00 to 1.00');
        return false;
    }
</script>
</head>
<body>
    <form id="form1" runat="server">

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

    </form>
</body>
</html>
   
Comments
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