Devexpress日历控件不断加载

时间:2016-09-18 13:03:03

标签: c# html asp.net calendar devexpress

我正在使用 Devexpress 日历控件来禁用某些日期并更改文本值,即我通过将前导0与它们连接来更改小于10的日期。例如,从1,2,3到01,02,03等。为此我正在触发它的Cell Initialize和Cell Prepared Event。它确实工作正常,但当我导航到另一个月它继续loading它为什么这样做? 如果它不会以这种方式解决,请提出替代方案。

我的代码到目前为止:
C#Codebehind:

protected void ASPxDateEdit1_CalendarDayCellPrepared(object sender, CalendarDayCellPreparedEventArgs e)
    {
        int Date;
        bool isValidDate = int.TryParse(e.Date.Day.ToString(), out Date);
        if (isValidDate)
        {
            if (Date > 0 && Date < 10)
            {
                e.Cell.Text = "0" + e.Date.Day.ToString();
            }
        }

    }

ASPX:

<dx:ASPxPopupControl ClientInstanceName="ASPxPopupClientControl" Width="300px" Height="150px"
    MaxWidth="800px" MaxHeight="300px" MinHeight="150px" MinWidth="150px" ID="pcMain"
    ShowFooter="True" FooterText="HolidayIn" PopupElementID="d1" HeaderText="Select Date From"
    runat="server" EnableViewState="false" PopupHorizontalAlign="LeftSides" PopupVerticalAlign="Below" EnableHierarchyRecreation="True">
    <ContentCollection>
        <dx:PopupControlContentControl runat="server">
            <asp:Panel ID="Panel1" runat="server">
                <table>
                    <tr>
                        <td style="color: #666666;">
                            <div style="float: left">
                                <dx:ASPxCalendar ID="ASPxCalendar" EnableTheming="true" HeaderStyle-CssClass="MainHeader" CssClass="Align"
                                    HeaderStyle-Paddings-PaddingLeft="70px" HeaderStyle-Cursor="pointer" ShowDayHeaders="true" ShowClearButton="false" ShowTodayButton="false"
                                    TodayButtonText="Today's Date" RootStyle-Wrap="True" DayStyle-CssClass="DayStyle" ShowWeekNumbers="false" Height="200px" Width="300px"
                                    HighlightWeekends="true" HighlightToday="true" DayHeaderStyle-CssClass="Header" Theme="Office2003Blue" runat="server"
                                    DayDisabledStyle-BackColor="White" DayDisabledStyle-Font-Strikeout="true" OnDayCellPrepared="ASPxDateEdit1_CalendarDayCellPrepared">
                                </dx:ASPxCalendar>
                            </div>
                        </td>
                    </tr>
                </table>
            </asp:Panel>
        </dx:PopupControlContentControl>
    </ContentCollection>
    <ClientSideEvents CloseUp="function(s, e) { SetImageState(false); }" PopUp="function(s, e) { SetImageState(true); }" />
</dx:ASPxPopupControl>

以下是它在加载并卡在那里时的样子: Picture

注意:我正在尝试将日历控件的日期单元格对齐,因为它们在页面上保持不正确。我也附上了快照。

正确格式化日历控件:
Correct
格式不正确的日历控件:
Incorrect

1 个答案:

答案 0 :(得分:0)

听起来,当您不想要它时,会调用日历操作。要防止事件在您不希望事件发生时触发,请在不希望触发时将其包装在bool设置为false中,并在执行时将其包装为true。类似的东西:

bool isLoading = true;
protected void Page_Load(object sender, EventArgs e)
    {
        //if(isPostBack){
            isLoading = true;
            //do your other form loading stuff
            isLoading=false;
       // }

    }
 protected void ASPxDateEdit1_CalendarDayCellPrepared(object sender, CalendarDayCellPreparedEventArgs e)
{
    if(!isLoading)
    {
        isLoading = true;
        int Date;
        bool isValidDate = int.TryParse(e.Date.Day.ToString(), out Date);
        if (isValidDate)
        {
            if (Date > 0 && Date < 10)
            {
                e.Cell.Text = "0" + e.Date.Day.ToString();
            }
        }
        isLoading = false;
    }
}