如何在modalpopupextender中使用验证控件

时间:2012-02-02 15:31:12

标签: asp.net asp.net-ajax ajaxcontroltoolkit

我在GridView中使用ModalPopupExtender。当用户单击网格中的链接按钮以更新行值时,将打开模态弹出窗口。用户更新值并单击更新按钮。

我在模态弹出窗口中使用了验证控件,但是当用户单击更新按钮时,表单提交而不验证控件。

我尝试使用ValidationGroup,因为它在一些论坛中提到但没有运气。任何人都可以帮助解决这个或任何好的例子。

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>

</div><asp:Button ID="btnShowPopup" runat="server" Text="Button" style="display:none"/><div >
    <asp:GridView ID="GridView2" runat="server" BackColor="White" 
        BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" 
        AutoGenerateColumns="False" ForeColor="Black" Width="100%" 
        onrowcreated="GridView2_RowCreated" onrowdatabound="GridView2_RowDataBound">
        <Columns>
            <asp:BoundField DataField="ShortDescription" HeaderText="ShortDescription" ReadOnly="True" ><ItemStyle Width="32%" /></asp:BoundField>
            <asp:BoundField DataField="Planned" HeaderText="Planned" ReadOnly="True" >
            <ItemStyle Width="5%" HorizontalAlign="Right" /></asp:BoundField>
            <asp:BoundField DataField="Actual" HeaderText="Actual" ReadOnly="True" >
            <ItemStyle Width="5%" HorizontalAlign="Right" /></asp:BoundField>
            <asp:BoundField DataField="Error" HeaderText="Error" ReadOnly="True" >
            <ItemStyle Width="5%" HorizontalAlign="Right" /></asp:BoundField>
            <asp:BoundField DataField="Volume" HeaderText="Vol" ReadOnly="True" 
                DataFormatString="{0:#%}" >
            <ItemStyle Width="3%" HorizontalAlign="Right" /></asp:BoundField>
            <asp:BoundField DataField="Mix" HeaderText="Mix" ReadOnly="True" 
                DataFormatString="{0:#%}" >
            <ItemStyle Width="3%" HorizontalAlign="Right" /></asp:BoundField>
            <asp:BoundField DataField="PMReason" HeaderText="Reason" ><ItemStyle Width="9%" /></asp:BoundField>
            <asp:BoundField DataField="PMComment" HeaderText="Comment" ><ItemStyle Width="9%" /></asp:BoundField>
            <asp:BoundField DataField="PMPlanned" HeaderText="Planned" >
            <ItemStyle Width="5%" HorizontalAlign="Right" /></asp:BoundField>
            <asp:BoundField DataField="PMActual" HeaderText="Actual" ReadOnly="True" >
            <ItemStyle Width="5%" HorizontalAlign="Right" /></asp:BoundField>
            <asp:BoundField DataField="PMError" HeaderText="Error" >
            <ItemStyle Width="5%" 
                HorizontalAlign="Right" /></asp:BoundField>
            <asp:BoundField DataField="PMVolume" HeaderText="Vol" ReadOnly="True" 
                DataFormatString="{0:#%}" >
            <ItemStyle Width="3%" HorizontalAlign="Right" /></asp:BoundField>
            <asp:BoundField DataField="PMMix" HeaderText="Mix" ReadOnly="True" 
                DataFormatString="{0:#%}" >
            <ItemStyle Width="3%" HorizontalAlign="Right" /></asp:BoundField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:ImageButton ID="btnSelect" runat="server" CausesValidation="false"
                            ImageUrl="~/Images/edit.png"
                            ImageAlign="AbsMiddle" Height="15px" Width="15px" 
                        onclick="btnSelect_Click" />
                </ItemTemplate>
                <ItemStyle Width="3%" />
            </asp:TemplateField>
            <asp:BoundField DataField="ReportRowId" Visible="False" />
        </Columns>
        <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
        <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
        <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
    </asp:GridView>
    </div>

    <cc2:ModalPopupExtender ID="gv_ModalPopupExtender" runat="server"
                                     TargetControlID="btnShowPopup"
                                     PopupControlID="pnlModalPanel"
                                     CancelControlID="btnCancel"
                                     BackgroundCssClass="modalBackground"/>

    <asp:Panel ID="pnlModalPanel" runat="server" Style="display: none;" BackColor="Red">
        <table>
            <tr>
                <th colspan="2" align="center" style="color:White; font-size:larger"> POST MITIGATION </th>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblRowId" runat="server" Style="display: none;"></asp:Label> </td>
                <td></td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblDevice" runat="server" 
                               ForeColor="White" Font-Bold="True">Device:</asp:Label> </td>
                <td><asp:TextBox ID="txtDevice" runat="server" Width="150px" ReadOnly="true"></asp:TextBox></td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblPlanned" runat="server" 
                               ForeColor="White" Font-Bold="True">Planned:</asp:Label> </td>
                <td><asp:TextBox ID="txtPlanned" runat="server" Width="150px" ReadOnly="true"></asp:TextBox></td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblActual" runat="server" 
                               ForeColor="White" Font-Bold="True">Actual:</asp:Label> </td>
                <td><asp:TextBox ID="txtActual" runat="server" Width="150px"></asp:TextBox></td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblError" runat="server" 
                               ForeColor="White" Font-Bold="True">Error:</asp:Label> </td>
                <td><asp:TextBox ID="txtError" runat="server" Width="150px" ReadOnly="true"></asp:TextBox></td>
            </tr>

            <tr>
                <td>
                    <asp:Label ID="lblReason" runat="server" 
                               ForeColor="White" Font-Bold="True">Reason:</asp:Label> </td>
                <td>
                    <asp:DropDownList ID="ddlReason" runat="server" Width="150px" ValidationGroup="valReason">
                        <asp:ListItem>-- Select Reason --</asp:ListItem>
                        <asp:ListItem></asp:ListItem>
                        <asp:ListItem>Availability LT</asp:ListItem>
                        <asp:ListItem>Availability ST</asp:ListItem>
                        <asp:ListItem>Competitor Response</asp:ListItem>
                        <asp:ListItem>Credit</asp:ListItem>
                        <asp:ListItem>Plan Issue</asp:ListItem>
                        <asp:ListItem>Props Change</asp:ListItem>
                        <asp:ListItem>SCL Request</asp:ListItem>
                        <asp:ListItem>Launch Delay</asp:ListItem>
                        <asp:ListItem>Launch Forward</asp:ListItem>
                        <asp:ListItem>Phasing</asp:ListItem>
                        <asp:ListItem>Opportunity-Positive</asp:ListItem>
                        <asp:ListItem>Opportunity-Negative</asp:ListItem>
                    </asp:DropDownList>
                <asp:RequiredFieldValidator ID="rfvReason" ValidationGroup="valReason" runat="server" Text="*" ErrorMessage="RequiredFieldValidator" 
                     ControlToValidate="ddlReason" Display="Dynamic" ForeColor="White" InitialValue="-- Select Reason --"></asp:RequiredFieldValidator></td>
            </tr>

            <tr>
                <td>
                    <asp:Label ID="lblComment" runat="server" 
                               ForeColor="White" Font-Bold="True">Comment:</asp:Label> </td>
                <td><asp:TextBox ID="txtComment" TextMode="MultiLine" Height="50px" runat="server" Width="150px"></asp:TextBox></td>
            </tr>

            <tr>
                <td colspan="2" align="center">
                    <asp:Button ID="btnUpdate" runat="server" CausesValidation="true" ValidationGroup="valReason" 
                                Text="Update Mitigation" onclick="btnUpdate_Click" />
                    <asp:Button ID="btnCancel" runat="server" Text="Cancel"/></td>
            </tr>
        </table>
    </asp:Panel>


</ContentTemplate>
</asp:UpdatePanel>

1 个答案:

答案 0 :(得分:0)

当我从面板中删除更新按钮并将其替换为新按钮时,它工作正常。

但我不确定为什么它之前没有用,为什么它现在正在工作。它的代码完全相同。看起来很奇怪。