0

我有这个带有 3 个窗格的手风琴。在其中一个窗格上,有一个按钮应该引发点击事件,但它没有。我试图删除所有不起作用的验证器,删除不起作用的 CalendarExtenders,将按钮放在不起作用的手风琴外面,用不起作用的按钮注释掉手风琴,注释掉不起作用的日历,但是当我注释掉日历和手风琴时,它会正确触发事件。我通过在正确的方法中放置一个断点来检查它是否会触发,并且当它不起作用时请求也会超时。

标记如下:

<div id="container">
    <div id="calendar">
        <asp:calendar id="Calendar1" runat="server" backcolor="#6dc066" bordercolor="#000000" borderwidth="2px" font-names="Verdana" font-size="1.2em" forecolor="White" height="400px" width="400px" style="margin-right: 0px" cellpadding="4" daynameformat="Shortest" ondayrender="Calendar1_DayRender" onselectionchanged="Calendar1_SelectionChanged">
            <DayHeaderStyle BackColor="#666666" Font-Bold="True" Font-Size="9pt" />
            <NextPrevStyle VerticalAlign="Bottom" />
            <OtherMonthDayStyle ForeColor="#000000" />
            <TitleStyle BackColor="#494949" BorderColor="Black" Font-Bold="True" />
            <TodayDayStyle BackColor="#FFFFFF" ForeColor="Black" />
            <WeekendDayStyle BackColor="#487346"/>
        </asp:calendar>
    </div>
    <div class="accordion-div">
        <asp:Accordion ID="MyAccordion" runat="Server" HeaderCssClass="accordionHeader" HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordion" TransitionDuration="250" FramesPerSecond="40" RequireOpenedPane="true" SuppressHeaderPostbacks="true">
            <Panes>
                <asp:AccordionPane runat="server" ID="InfoPane">
                    <header>Informationer om valgt dato</header>
                    <Content>
                        <div style="margin: 5px;">
                            <b>Startdato: </b><asp:Label runat="server" ID="startLabel" />
                            <br />
                            <b>Slutdato: </b><asp:Label runat="server" ID="endLabel" />
                            <br />
                            <b>Reserveret af: </b><asp:Label runat="server" ID="authorLabel" />
                            <br />
                            <b>Kommentarer: </b><asp:Label runat="server" ID="commentsLabel" />
                            <br />
                            <b>Reserveringstidspunkt: </b><asp:Label runat="server" ID="bookedTimeLabel" />
                        </div>
                    </Content>
                </asp:AccordionPane>
                <asp:AccordionPane runat="server" ID="BookingPane">
                    <Header>Reservering</Header>
                    <Content>
                        <div style="margin-left: 10px; width: 350px;">
                            <h3>Reserver:</h3>
                            <p>
                                <b>Startdato: </b><asp:TextBox runat="server" ID="txtStart" CausesValidation="true" CssClass="right-align"></asp:TextBox>
                                <asp:CalendarExtender FirstDayOfWeek="Monday" ID="txtStart_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtStart" Format="dd/MM/yyyy">
                                </asp:CalendarExtender>
                                <asp:RequiredFieldValidator ID="StartRequired" ControlToValidate="txtStart" runat="server" ErrorMessage="Udfyldelse er påkrævet" Display="Dynamic"/>
                                <asp:RangeValidator ID="StartRange" ControlToValidate="txtStart" runat="server" ErrorMessage="Startdato skal være efter i dag" Type="Date" Display="Dynamic"/>
                                <br />
                            </p>
                            <p>
                                <b>Slutdato: </b><asp:TextBox runat="server" ID="txtEnd" CausesValidation="true" CssClass="right-align"></asp:TextBox>
                                <asp:CalendarExtender FirstDayOfWeek="Monday" ID="txtEnd_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtEnd" Format="dd/MM/yyyy">
                                </asp:CalendarExtender>
                                <asp:RequiredFieldValidator ID="EndRequired" ControlToValidate="txtEnd" runat="server" ErrorMessage="Udfyldelse er påkrævet" Display="Dynamic"/>
                                <asp:RangeValidator ID="EndRange" ControlToValidate="txtEnd" runat="server" ErrorMessage="Slutdato skal være efter i dag" Type="Date" Display="Dynamic"/>
                                <br />
                            </p>
                            <p>
                                <b>Kommentar: </b><asp:TextBox runat="server" ID="txtComment" CssClass="right-align"></asp:TextBox>  
                                <br />
                            </p>
                            <p>
                                <asp:CustomValidator runat="server" ID="customVal" ControlToValidate="txtEnd" ErrorMessage="En af de valgte dag er booket" OnServerValidate="customVal_ServerValidate" Display="Dynamic"/>
                                <asp:CompareValidator runat="server" ControlToValidate="txtStart" ErrorMessage="Startdatoen skal være før slutdatoen" ControlToCompare="txtEnd" Operator="LessThanEqual" Type="Date" Display="Dynamic"/>
                                <br />
                                <asp:Button ID="BookButton" runat="server" OnClick="BookButton_Click" Text="Reserver" BackColor="LightGray" BorderStyle="Solid" BorderColor="Black"/>
                                <br />
                                <asp:Label runat="server" ID="SuccesLabel" Visible="false" BackColor="LightGreen"/>
                            </p>
                        </div>
                    </Content>
                </asp:AccordionPane>
                <asp:AccordionPane runat="server" ID="MyReservationPane">
                    <header>Mine reservationer</header>
                </asp:AccordionPane>
            </Panes>
        </asp:Accordion>
    </div>
</div>

提前致谢

4

1 回答 1

1

我测试了你的代码。它表明您遇到日期格式不匹配的问题。当您在日历扩展器中将日期格式设置为英国时,但范围验证器会根据美国日期格式进行评估。因此,阻止您在按钮单击时回发。

如果是这种情况,您可以在 Page_Load(后面的代码)中添加以下内容:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");

这应该可以解决您的问题。

于 2013-05-07T07:33:58.173 回答