2016-09-18 81 views
0

我正在使用Devexpress日曆控件禁用某些日期並在那裏更改文本值,即我通過將前導0與它們連接來更改小於10的日期。例如從1,2,3到01,02,03等等。爲此我觸發了它的單元初始化和單元準備事件。它確實工作正常,但當我導航到另一個月,它保持在loading爲什麼它這樣做? 如果不能用這種方法解決,請提出替代方案。Devexpress日曆控件不斷加載

到目前爲止我的代碼:
C#代碼隱藏:

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

注意:我想對齊日曆控件的日期單元格,因爲它們不保留在頁面上。我也附上快照。

正確格式化Calendar控件:
Correct
不正確格式化Calendar控件:
Incorrect

回答

0

這聽起來像您的日曆操作被稱爲當你不希望它。爲了防止你的事件在你不想要的時候被觸發,當你不想讓它觸發的時候,把它設置爲false,當你這樣做的時候將它包裝成false。例如:

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; 
    } 
} 
+0

它沒有工作,除了'布爾isLoading'我甚至嘗試'ViewState'也。 – CodeIt

+0

但是,我認爲每次我們導航到下個月時都會觸發 – CodeIt

+0

要測試,您可以取消註冊ASPxDateEdit1_CalendarDayCellPrepared並將其綁定到按鈕單擊 - 看看是否可以解決問題。如果是這樣,那麼這是一個尋找ASPxDateEdit1_CalendarDayCellPrepared何時觸發並在不需要時阻止它執行的問題。 –