2

私は次のようなカレンダーセレクターを持っています

<asp:ImageButton ID="calStartImage" runat="server" ImageUrl="../images/SmallCalendar.gif"
                        AlternateText="Please select start date"  />
                    <ajaxToolkit:CalendarExtender ID="calStartDate" runat="server" TargetControlID="txtStartDate"
                        Format="MM/dd/yyyy" PopupButtonID="calStartImage" />

そしてこのような検索ボタン

 <asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click"
                            CausesValidation="false" />

カレンダーから日付を選択して検索を押すと、初めてbtnSearch_Clickが起動しません。もう一度[検索]をクリックすると、正常に機能します。したがって、クリックイベントが機能する前に、[検索]ボタンを2回クリックする必要があります。これは、カレンダーコントロールから日付を選択した場合にのみ発生します。

フルコントロールは次のとおりです。

 <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </ajaxToolkit:ToolkitScriptManager>
    <table>
        <tr>
            <td class="SearchBox">
                <table>
                    <tr>
                        <td colspan="2">
                            <b>Enter name to filter results</b>&nbsp;&nbsp;&nbsp;&nbsp;
                            <asp:TextBox ID="txtProjectName" runat="server"></asp:TextBox><br />
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td valign="middle">
                            <b>From:</b>
                            <asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>
                            <asp:ImageButton ID="calStartImage" runat="server" ImageUrl="../images/SmallCalendar.gif"
                                AlternateText="Please select start date" />
                            <ajaxToolkit:CalendarExtender ID="calStartDate" runat="server" TargetControlID="txtStartDate"
                                Format="MM/dd/yyyy" PopupButtonID="calStartImage" />
                            &nbsp;&nbsp;&nbsp;&nbsp; <b>Thru:</b>
                            <asp:TextBox ID="txtEndDate" runat="server"></asp:TextBox>
                            <asp:ImageButton runat="server" ID="calEndImage" ImageUrl="../images/SmallCalendar.gif"
                                AlternateText="Please select end date" />
                            <ajaxToolkit:CalendarExtender ID="calEndDate" runat="server" TargetControlID="txtEndDate"
                                Format="MM/dd/yyyy" PopupButtonID="calEndImage" />
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="From Date is Required"
                                ControlToValidate="txtStartDate" Display="Dynamic"></asp:RequiredFieldValidator>&nbsp;&nbsp;
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Thru Date is Required"
                                ControlToValidate="txtEndDate" Display="Dynamic"></asp:RequiredFieldValidator>&nbsp;&nbsp;
                            <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Invalid From Date"
                                ControlToValidate="txtStartDate" Display="Dynamic" MaximumValue="1/1/2099" MinimumValue="1/1/2006"
                                SetFocusOnError="True" Type="Date"></asp:RangeValidator>&nbsp;&nbsp;
                            <asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="txtEndDate"
                                ErrorMessage="Invalid Thru Date" SetFocusOnError="True" Type="Date" Display="Dynamic"
                                MaximumValue="1/1/2999" MinimumValue="1/1/2006"></asp:RangeValidator>&nbsp;&nbsp;&nbsp;
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td align="left">
                            <asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click"
                                CausesValidation="false" />
                        </td>
                    </tr>
                </table>
            </td>
            <td align="right" style="width:560px">
                <a href="../Contents/docs/Guide.pdf" target="_blank">Guide</a> &nbsp;&nbsp;
            </td>
        </tr>
    </table>

こちらがページからの詳細です。

 <ajaxToolkit:ModalPopupExtender ID="mdlPopupExtender" runat="server" TargetControlID="btnShowPopup"
        PopupControlID="pnlProject" BackgroundCssClass="modalBackground" Drag="true"
        DropShadow="true" CancelControlID="btnClose" PopupDragHandleControlID="TitleBar">
    </ajaxToolkit:ModalPopupExtender>
    <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
    <asp:Panel ID="pnlProject" runat="server" BackColor="WhiteSmoke">
        <asp:Panel ID="TitleBar" runat="server" CssClass="modalPopupTitleBar">
            Add/Edit Project
        </asp:Panel>
        <asp:UpdatePanel ID="upPopList" runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnAddNew" EventName="Click" />
            </Triggers>
            <ContentTemplate>
                <table cellspacing="10">
                    <tr>
                        <td colspan="2">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <b>Project Name:</b>
                        </td>
                        <td>
                            <asp:TextBox ID="txtProject" runat="server" Width="200px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="reqProject" runat="server" ErrorMessage="Required!"
                                Display="Dynamic" ControlToValidate="txtProject"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <b>Field Office:</b>
                        </td>
                        <td>
                            <asp:TextBox ID="txtFieldOffice" runat="server" Width="200px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="reqFieldOffice" runat="server" ErrorMessage="Required!"
                                Display="Dynamic" ControlToValidate="txtFieldOffice"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <b>Created By:</b>
                        </td>
                        <td>
                            <asp:Label ID="lblCreatedBy" runat="server"></asp:Label>
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
        <table>
            <tr>
                <td>
                    <br />
                    &nbsp;&nbsp;<asp:Button ID="btnSubmit" runat="server" Text="Save" OnClick="btnSubmit_Click" />&nbsp;&nbsp;&nbsp;
                    <asp:Button ID="btnClose" runat="server" Text="Close" CausesValidation="false" />
                    <br />
                </td>
            </tr>
        </table>
    </asp:Panel>

何か案は?

4

2 に答える 2

1

各検証グループが特定のページの他の検証グループとは独立して検証を実行できるように、検証コントロールに ValidationGroup を追加する必要があります。詳細はこちらで確認できます検証グループの指定

グループ検証を使用したコードを次に示します。環境に合わせて変更できます。

<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <table>
        <tr>
            <td>
                <table>
                    <tr>
                        <td colspan="2">
                            <b>Enter name to filter results</b>&nbsp;&nbsp;&nbsp;&nbsp;
                            <asp:TextBox ID="txtProjectName" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td valign="middle">
                            <b>From:</b>
                            <asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="formDateRequiredValidator" ValidationGroup="Date"
                                runat="server" ErrorMessage="Enter From Date." ControlToValidate="txtStartDate"></asp:RequiredFieldValidator>
                            <asp:RangeValidator ID="RangeValidator1" runat="server" ValidationGroup="Date" ErrorMessage="Invalid From Date"
                                ControlToValidate="txtStartDate" Display="Dynamic" MaximumValue="1/1/2099" MinimumValue="1/1/2006"
                                SetFocusOnError="True" Type="Date"></asp:RangeValidator>&nbsp;&nbsp;
                            <asp:ImageButton ID="calStartImage" runat="server" AlternateText="Please select start date" />
                            <asp:CalendarExtender ID="calStartDate" runat="server" TargetControlID="txtStartDate"
                                Format="MM/dd/yyyy" PopupButtonID="calStartImage" />
                            &nbsp;&nbsp;&nbsp;&nbsp; <b>Thru:</b>
                            <asp:TextBox ID="txtEndDate" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="endDateRequiredValidator" ValidationGroup="Date"
                                runat="server" ErrorMessage="Enter Thru Date." ControlToValidate="txtEndDate"></asp:RequiredFieldValidator>
                            <asp:RangeValidator ID="RangeValidator2" ValidationGroup="Date" runat="server" ErrorMessage="Invalid From Date"
                                ControlToValidate="txtStartDate" Display="Dynamic" MaximumValue="1/1/2099" MinimumValue="1/1/2006"
                                SetFocusOnError="True" Type="Date"></asp:RangeValidator>&nbsp
                            <asp:ImageButton runat="server" ID="calEndImage" ImageUrl="../images/SmallCalendar.gif"
                                AlternateText="Please select end date" />
                            <asp:CalendarExtender ID="calEndDate" runat="server" TargetControlID="txtEndDate"
                                Format="MM/dd/yyyy" PopupButtonID="calEndImage" />
                        </td>
                    </tr>
                    <tr>
                        <td align="left">
                            <asp:Button ID="btnSearch" runat="server" Text="Search" ValidationGroup="Date" CausesValidation="false" />
                        </td>
                    </tr>
                </table>
            </td>
            <td align="right">
                <a href="../Contents/docs/Guide.pdf" target="_blank">Guide</a> &nbsp;&nbsp;
            </td>
        </tr>
    </table>
    <asp:ModalPopupExtender ID="mdlPopupExtender" runat="server" TargetControlID="btnShowPopup"
        PopupControlID="pnlProject" BackgroundCssClass="modalBackground" Drag="true"
        DropShadow="true" CancelControlID="btnClose" PopupDragHandleControlID="TitleBar">
    </asp:ModalPopupExtender>
    <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
    <asp:Panel ID="pnlProject" runat="server" BackColor="WhiteSmoke">
        <asp:Panel ID="TitleBar" runat="server">
            Add/Edit Project
        <%-- I have added this Button you can replace with yours becaus specified in Triggers to run the code i need to add this(btnAddNew) Button--%>
            <asp:Button ID="btnAddNew" runat="server" Text="AddNew" />
        </asp:Panel>
        <asp:UpdatePanel ID="upPopList" runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnAddNew" />
            </Triggers>
            <ContentTemplate>
                <table>
                    <tr>
                        <td colspan="2">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <b>Project Name:</b>
                        </td>
                        <td>
                            <asp:TextBox ID="txtProject" runat="server" Width="200px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="reqProject" ValidationGroup="ProjectInfo" runat="server"
                                ErrorMessage="Required!" Display="Dynamic" ControlToValidate="txtProject"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <b>Field Office:</b>
                        </td>
                        <td>
                            <asp:TextBox ID="txtFieldOffice" runat="server" Width="200px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="reqFieldOffice" ValidationGroup="ProjectInfo" runat="server"
                                ErrorMessage="Required!" Display="Dynamic" ControlToValidate="txtFieldOffice"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    </td> </tr>
                    <tr>
                        <td>
                            <b>Created By:</b>
                        </td>
                        <td>
                            <asp:Label ID="lblCreatedBy" runat="server"></asp:Label>
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
        <table>
            <tr>
                <td>
                    <br />
                    &nbsp;&nbsp;<asp:Button ID="btnSubmit" runat="server" Text="Save" OnClick="btnSubmit_Click" />&nbsp;&nbsp;&nbsp;
                    <asp:Button ID="btnClose" runat="server" Text="Close" CausesValidation="false" ValidationGroup="ProjectInfo"
                        OnClick="btnClose_Click" />
                    <br />
                </td>
            </tr>
        </table>
    </asp:Panel>

お役に立てれば。

于 2012-06-17T05:00:18.020 に答える
0

理由はわかりませんが、のCausesValidationプロパティをbtnSearchに設定することで問題を解決できますtrue

<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click"
     CausesValidation="true" />
于 2012-06-12T15:32:40.393 に答える