验证在GridView控件在EditItemTemplate中工作不适合文本框 [英] Validation in GridView not working for TextBox in EditItemTemplate

查看:171
本文介绍了验证在GridView控件在EditItemTemplate中工作不适合文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个 RegularEx pressionValidator 中的 EditItemTemplate中在一个文本框 GridView控件控制。

当用户点击更新,如果输入错误,验证工作(错误信息可见)。但是,在 OnRowUpdating 方法,我有 Page.IsValid ==真。为什么会出现这种情况?

ASPX code:

 < ASP:GridView控件ID =dgvsaldoPV=服务器可见=假的AutoGenerateColumns =FALSE
        ShowFooter =真AllowSorting =真OnSorting =TaskGridView_SortingSaldoPVOnRowEditing =gv1_RowEditing
        OnRowUpdating =gv1_RowUpdatingonRowCancelingEdit =gv1_RowCancelingEdit的DataKeyNames =ID_CASSA>
        < AlternatingRowStyle背景色=#FFFFCC/>
        <柱体和GT;            < ASP:的TemplateField的HeaderText =SaldoInsertVisible =FALSESORTEX pression =SALDO>
                <&EditItemTemplate的GT;
                    < ASP:文本框ID =txtsaldo=服务器的ValidationGroup =saldo文本='<%#绑定(SALDO)%>'>< / ASP:文本框>
                    < ASP:RegularEx pressionValidator ID =RegularEx pressionValidator1=服务器的ControlToValidate =txtsaldo
                的ErrorMessage =Inserisci valori numerici,usare,我每decimaliValidationEx pression =^ \\ D * \\,?\\ D + $的ValidationGroup =saldo
                    前景色=红>< / ASP:RegularEx pressionValidator>
                < / EditItemTemplate中>
                <&ItemTemplate中GT;
                    < ASP:标签ID =Label1的=服务器文本='<%#绑定(SALDO)%>'>< / ASP:标签>
                < / ItemTemplate中>
                < ItemStyle的CssClass =style11/>
            < / ASP:的TemplateField>            < ASP:CommandField中ShowEditButton =真ShowHeader =false的HeaderStyle-的CssClass =headerstyle1/>
        < /专栏>
        < FooterStyle背景色=#CC0000前景色=白/>
        < HeaderStyle的CssClass =headerstyle/>
        < RowStyle Horizo​​ntalAlign =中心VerticalAlign =中/>    < / ASP:GridView的>


解决方案

尝试调用

  Page.Validate();

你的 GridView.RowUpdating 事件的开始。这将迫使所有的服务器端验证器的检查。我希望,这已被称为由点,但它听起来像并非如此。

如果你的 GridView控件里面的的UpdatePanel 做一个局部回传,或者是造成回发火灾控制未设置为导致验证(这是 .CausesValidation 属性设置为false),那么我可以想像 Page.IsValid 属性没有被正确填充呢。

I am trying to add a RegularExpressionValidator for a textbox in an EditItemTemplate in a GridView control.

When a user clicks on "update", if the input is wrong, the validator work (error message is visible). But, in the OnRowUpdating method, I have Page.IsValid==true. Why is this happening?

ASPX code:

<asp:GridView ID="dgvsaldoPV" runat="server" Visible="False" AutoGenerateColumns="False" 
        ShowFooter="True" AllowSorting="True" OnSorting="TaskGridView_SortingSaldoPV" OnRowEditing="gv1_RowEditing" 
        OnRowUpdating="gv1_RowUpdating" onRowCancelingEdit="gv1_RowCancelingEdit" DataKeyNames="ID_CASSA">
        <AlternatingRowStyle BackColor="#FFFFCC" />
        <Columns>

            <asp:TemplateField HeaderText="Saldo" InsertVisible="False" SortExpression="SALDO" >
                <EditItemTemplate >
                    <asp:TextBox ID="txtsaldo" runat="server" validationgroup="saldo" Text='<%# Bind("SALDO") %>'></asp:TextBox>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtsaldo"
                ErrorMessage="Inserisci valori numerici, usare ',' per i decimali" ValidationExpression="^\d*\,?\d+$" validationgroup="saldo"
                    ForeColor="Red" ></asp:RegularExpressionValidator>
                </EditItemTemplate>
                <ItemTemplate >
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("SALDO") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle CssClass="style11"    />
            </asp:TemplateField>

            <asp:CommandField ShowEditButton="True" ShowHeader="false" HeaderStyle-CssClass="headerstyle1"/>
        </Columns>
        <FooterStyle BackColor="#CC0000" ForeColor="White" />
        <HeaderStyle CssClass="headerstyle" />
        <RowStyle HorizontalAlign="Center" VerticalAlign="Middle"/>

    </asp:GridView>

解决方案

Try calling

Page.Validate();

at the beginning of your GridView.RowUpdating event. This will force a check of all the server-side validators. I would expect that this had already been called by that point, but it sounds like that's not the case.

If your GridView is inside an UpdatePanel doing a partial PostBack, or the control that's causing the PostBack to fire is not set to cause validation (it's .CausesValidation property is set to false), then I could imagine the Page.IsValid property not being properly populated yet.

这篇关于验证在GridView控件在EditItemTemplate中工作不适合文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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