search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Next and Previous Navigation Jump Double

Asked by Anonymous
6 years ago.

I'm having a weird issue. I've added buttons for "Previous", "Today", and "Next" to jump to the next or previous day, week, or month. I copy and pasted the sample code from your tutorial but no matter what i do, every time i press the "next" or "previous" buttons it will jump twice the intended value. If i am in Day View and today is the 15th, it will load the 17th when "next" is pressed, and the 13th when "previous" is pressed. "Today" is the only thing that works. Below is the code for DayView. But it happens the same for Month View and Week View. In Month View it will jump to March (this month is January). In week view it will jump 14 days instead of 7. Below is the code being used on DayView. It is the same for Week and Month except for what is being added. I'm using the newest version of DayPilotPro 8.4.3630. Any help would be appreciated.

<div class="space">
Day:
<a href="javascript:dp_day.commandCallBack('previous');">Previous</a>
|
<a href="javascript:dp_day.commandCallBack('today');">Today</a>
|
<a href="javascript:dp_day.commandCallBack('next');">Next</a>
</div>

Protected Sub DayPilotCalendarDay_Command(ByVal sender As Object, ByVal e As DayPilot.Web.Ui.Events.CommandEventArgs) Handles DayPilotCalendarDay.Command
Select Case e.Command

Case "previous"

DayPilotCalendarDay.StartDate = DayPilotCalendarDay.StartDate.AddDays(-1)
DayPilotCalendarDay.DataBind()
DayPilotCalendarDay.Update()

Case "next"

DayPilotCalendarDay.StartDate = DayPilotCalendarDay.StartDate.AddDays(1)
DayPilotCalendarDay.DataBind()
DayPilotCalendarDay.Update()

Case "today"

DayPilotCalendarDay.StartDate = DateTime.Today
DayPilotCalendarDay.DataSource = GetData(DateTime.Today, DateTime.Today.AddDays(1))
DayPilotCalendarDay.DataBind()
DayPilotCalendarDay.Update()

End Select
End Sub

Comment posted by Dan Letecky [DayPilot]
6 years ago.

If you check the StartDate value in DayPilotCalendarDay_Command() method, do you see the expected values?

Also, is DayPilotCalendarDay_Command() called once or twice?

Comment posted by Dan Letecky [DayPilot]
6 years ago.

Just a guess:

In VB.NET the event handler is defined using the "Handles" clause in the method signature (like you do):

Protected Sub DayPilotCalendarDay_Command(ByVal sender As Object, ByVal e As DayPilot.Web.Ui.Events.CommandEventArgs) Handles DayPilotCalendarDay.Command 
Select Case e.Command

However, it's also possible to define it in the .aspx template (this is usually used in C#):

<DayPilot:DayPilotCalendar OnCommand="DayPilotCalendarDay_Command" ... />

If you use both the event handler will be fired twice.

Comment posted by Anonymous
6 years ago.

I've done some testing and put a counter in the _Command() and it is being called twice. But i dont know how. I click the <a href="javascript:dp_day.commandCallBack('next');">Next</a> once but it jumps twice. What would cause it to be fired twice? For now i cheated. I added a counter on click and if it is equal to 1 then fire the calendar change, otherwise skip. Works fine but awful coding.

Answer posted by Anonymous
6 years ago.

Dan Letecky you are correct. It is being called twice because of the Handle and OnCommand both being used. I removed the OnCommand from the ASPX and all is well again. Thank you for the help.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.