如何通过访问具有客户端ID的文本框来验证动态网格视图中的文本框? [英] How to Validate the textbox inside the dynamic gridview by accessing the textbox with client ID ?

查看:70
本文介绍了如何通过访问具有客户端ID的文本框来验证动态网格视图中的文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是gridview中的代码,我在Add按钮上动态生成行。 


< ItemTemplate >
< asp:TextBox ID = txtweight_fact runat = server 高度 = 41px 宽度 = 42px

< span class =code-attribute> < span class =code-attribute> OnKeyPress = return isNumberKey(this,event); text = 0.00

MaxLength = 4 > < / asp:TextBox >
< br / >
< asp:RequiredFieldValidator ID = RequiredFieldValidator4 runat = server < span class =code-attribute>显示 = 动态

< span class =code-attribute> ControlToValidate = txtweight_fact ErrorMessage = * ValidationGroup = valgrp_func > < / asp:RequiredFieldValidator >

< < span class =code-leadattribute> / ItemTemplate >

添加按钮的代码
< FooterTemplate >
< span class =code-keyword>< center >
< asp:按钮 ID = Btn添加 runat = server OnClick = ButtonAdd_Click ValidationGroup = valgrp_func

文字 = 添加 / > < / center >
< / FooterTemplate >







我想用Idtxtweight_fact验证文本框但无法使用客户ID进行验证。

请建议解决方案。

问候

Ni!E $ #UPDATED

解决方案

#UPDATED


从这个例子改编:

 <%@     Page    语言  =  C#     AutoEventWireup   =  true    CodeFile   =  Default2.aspx.cs   继承  =   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 = 服务器 > ;
< title > ; < / title >
< script type = text / javascript >
function validateNumberRange(sender){
var e = sender;
var textboxVal = e.value;
if (textboxVal> = 0 00 && textboxVal< = 1 00 ){
返回 true ;
}
else
alert(' 请输入介于0.00到1.00之间的数字);
return false ;
}
< / 脚本 >
< / head >
< body >
< 表单 id = form1 runat < span class =code-keyword> = server >

< asp:GridView ID = GridView1 < span class =code-attribute> runat = server >
< >
< asp:TemplateField HeaderText = 文本框列 >
< ItemTemplate >
< asp:TextBox ID = textbox1 runat = server onkeyup = return validateNumberRange(this); / >
< / ItemTemplate >
< / asp:TemplateField >
< /列 >
< / asp:GridView >

< / form >
< / body >
< / html >


< blockquote>在这里参考..



Numeric-validation-for-TextBox-inside-GridView-using-JavaScript-or-jQuery-in-ASPNe

文本框只接受号码

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

解决方案

#UPDATED


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>


refer here..

Numeric-validation-for-TextBox-inside-GridView-using-JavaScript-or-jQuery-in-ASPNe
Text-box-to-accept-only-number


这篇关于如何通过访问具有客户端ID的文本框来验证动态网格视图中的文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆