必需的属性验证后,不会触发OnTextChanged

时间:2018-11-21 09:17:19

标签: c# asp.net

我有一个带有某些文本框的更新面板,并且我试图通过使用文本框上的required属性来替换requiredfieldvalidators,这使所有内容都更加简洁。测试仅需要第一个文本框。

<asp:UpdatePanel runat="server">
            <ContentTemplate>
                <table style="border-collapse: separate; border-spacing: 8px;">
                    <tbody>
                        <tr>
                            <td style="float: right;">
                                <asp:Label ID="lblRefCliente" runat="server" Text="Referência Cliente " ForeColor="#142658" Style="font-weight: bold;"></asp:Label><span style="color: red;">* </span>
                            </td>

                            <td>
                                <asp:TextBox ID="txtRefClient" CssClass="txtStyle" runat="server" required></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvRefClient" runat="server" ForeColor="red" ControlToValidate="txtRefClient" ErrorMessage=""></asp:RequiredFieldValidator>
                            </td>
                            <td style="float: right;">
                                <asp:Label ID="lblRefInterna" runat="server" Text="Referência Interna " ForeColor="#142658" Style="font-weight: bold;"></asp:Label><span style="color: red;">* </span>
                            </td>

                            <td>
                                <asp:TextBox ID="txtRefInterna" CssClass="txtStyle" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvRefInterna" runat="server" ForeColor="red" ControlToValidate="txtRefInterna" ErrorMessage=""></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td style="float: right;">
                                <asp:Label ID="lblIndice" runat="server" Text="Indíce " ForeColor="#142658" Style="font-weight: bold;"></asp:Label><span style="color: red;">* </span>
                            </td>
                            <td>
                                <asp:TextBox ID="txtIndice" CssClass="txtStyle" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvIndice" runat="server" ForeColor="red" ControlToValidate="txtIndice" ErrorMessage=""></asp:RequiredFieldValidator>
                            </td>
                            <td style="float: right;">
                                <asp:Label ID="lblProject" runat="server" Text="Projecto " ForeColor="#142658" Style="font-weight: bold;"></asp:Label><span style="color: red;">* </span>
                            </td>
                            <td>
                                <asp:TextBox ID="txtProject" CssClass="txtStyle" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvProject" runat="server" ForeColor="red" ControlToValidate="txtProject" ErrorMessage=""></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td style="float: right;">
                                <asp:Label ID="lblCadMensal" runat="server" Text="Cadência Mensal " ForeColor="#142658" Style="font-weight: bold;"></asp:Label><span style="color: red;">* </span>
                            </td>
                            <td>
                                <asp:TextBox ID="txtCadMensal" CssClass="txtStyle" AutoPostBack="true" runat="server" OnTextChanged="txtCadMensal_TextChanged"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvCadMensal" runat="server" ForeColor="red" ControlToValidate="txtCadMensal" ErrorMessage=""></asp:RequiredFieldValidator>                                    
                            </td>
                            <td style="float: right;">
                                <asp:Label ID="lblDesenho" runat="server" Text="Desenho " ForeColor="#142658" Style="font-weight: bold;"></asp:Label><span style="color: red;">* </span>
                            </td>
                            <td>
                                <asp:TextBox ID="txtDesenho" CssClass="txtStyle" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvDesenho" runat="server" ForeColor="red" ControlToValidate="txtDesenho" ErrorMessage=""></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td style="float: right;">
                                <asp:Label ID="lblNumCOMDEV" runat="server" Text="Nº de COMDEV " ForeColor="#142658" Style="font-weight: bold;"></asp:Label><span style="color: red;">* </span>
                            </td>
                            <td>
                                <asp:TextBox ID="txtNumCOMDEV" CssClass="txtStyle" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvNumCOMDEV" runat="server" ForeColor="red" ControlToValidate="txtNumCOMDEV" ErrorMessage=""></asp:RequiredFieldValidator>
                            </td>
                            <td style="float: right;">
                                <asp:Label ID="lblNumFormas" runat="server" Text="Nº Formas de Lançamento " ForeColor="#142658" Style="font-weight: bold;"></asp:Label><span style="color: red;">* </span>
                            </td>
                            <td>
                                <asp:TextBox ID="txtNumFormas" CssClass="txtStyle" runat="server" AutoPostBack="true" OnTextChanged="txtNumFormas_TextChanged"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvNumFormas" runat="server" ForeColor="red" ControlToValidate="txtNumFormas" ErrorMessage=""></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td style="float: right;">
                                <asp:Label ID="lblCapacidadeReal" runat="server" Text="Capacidade Real(métodos) " ForeColor="#142658" Style="font-weight: bold;"></asp:Label>
                            </td>
                            <td>
                                <asp:TextBox ID="txtCapacidadeReal" CssClass="txtStyle" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>

现在的问题是,我有这个文本框txtNumComps,它为某些输入创建了一些动态文本框,并执行OnTextChanged事件并正在执行它。问题是,当触发来自必需属性的验证时,OnTextChanged不会触发,只会触发第二次我写的东西。我看不到什么会导致此问题。如果有人可以帮助我将不胜感激。

<asp:UpdatePanel runat="server" ID="NumComps">
            <ContentTemplate>
                <table>
                    <tr>
                        <td>
                            <asp:Label ID="lblNumComps" runat="server" Text="Nº de Componentes " ForeColor="#142658" Style="font-weight: bold;"></asp:Label><span style="color: red; margin-right: 5px;"> * </span>
                        </td>
                        <td>

                            <asp:TextBox ID="txtNumComps" runat="server" AutoPostBack="True" OnTextChanged="txtNumComps_TextChanged"></asp:TextBox>
                        </td>
                        <td>
                            <asp:CustomValidator ID="cvNumComps" runat="server" ForeColor="red" ErrorMessage="" ControlToValidate="txtNumComps" ClientValidationFunction="NumpCompsValidator"></asp:CustomValidator>

                        </td>
                    </tr>
                </table>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="txtNumComps" EventName="TextChanged" />
            </Triggers>
        </asp:UpdatePanel>

0 个答案:

没有答案