使用验证组时更新面板不工作

时间:2015-03-23 11:18:46

标签: c# asp.net .net

我在更新面板中有以下内容:

<asp:UpdatePanel ID="upAddProduct" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <table border="0" cellpadding="2" cellspacing="2">
                <tr>
                    <td align="left">
                        <asp:Label ID="lblCaption" runat="server"></asp:Label>
                        :
                    </td>
                    <td align="left">
                        <asp:TextBox ID="txtValue" runat="server" ValidationGroup="NewValues"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="regInvData" ControlToValidate="txtValue" ErrorMessage="*"
                            runat="server" ValidationGroup="NewValues"></asp:RequiredFieldValidator>
                        <asp:HiddenField runat="server" ID="hdColType" />
                        <asp:HiddenField runat="server" ID="hdnSku" />
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        &nbsp;
                    </td>
                    <td align="left">
                        <asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="btnSubmit_Click"
                            ValidationGroup="NewValues" />
                    </td>
                </tr>
            </table>
        </ContentTemplate>
</asp:UpdatePanel>

当我点击上面代码中的提交按钮时,btnSubmit_Click不会被调用。

当我删除ValidationGroup="NewValues"

函数被调用。

在将其保存在更新面板之前,一切正常。

如何在上述情况下使用validationgroup?

请帮帮我。

1 个答案:

答案 0 :(得分:0)

试试这个,

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table border="0" cellpadding="2" cellspacing="2">
<tr>
<td align="left">
<asp:Label ID="lblCaption" runat="server"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtValue" runat="server" ValidationGroup="NewValues"> 
 </asp:TextBox>
<asp:RequiredFieldValidator ID="regInvData" ControlToValidate="txtValue"
ErrorMessage="*"
 runat="server" ValidationGroup="NewValues"></asp:RequiredFieldValidator>
<asp:HiddenField runat="server" ID="hdColType" />
<asp:HiddenField runat="server" ID="hdnSku" />
</td>
</tr>
<tr>
<td align="left">&nbsp;
</td>
<td align="left">
<asp:Button ID="btnSubmit" Text="Submit" runat="server" 
OnClick="btnSubmit_Click"  ValidationGroup="NewValues"
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>

它对我有用