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

Update Calendar from UpdatePanel button and vice versa

Asked by Jimmie Andersson
17 years ago.
Hi, just started to work with your trial, Love it!!

some questions, let me first show you some code:

<asp:UpdatePanel ID="uplEdit" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Literal ID="ltlEdit" runat="server" />
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="BtnAdd_Click" />
<br />

</ContentTemplate>
</asp:UpdatePanel>


<Daypilot:Daypilotcalendar
Id="dpcCalendar"
runat="server"

EventClickHandling="CallBack"
OnEventClick="DpcCalendar_EventClick"
/>

------------------
and code-behind:

protected void DpcCalendar_EventClick(object sender, DayPilot.Web.Ui.Events.EventClickEventArgs e)
{
ltlEdit.Text = DateTime.Now.ToLongTimeString() + " id: " + e.Value;
uplEdit.Update();
}


protected void BtnAdd_Click(object sender, EventArgs e)
{
FPCalendarEventFacad.CreateNewCalendarEvent(UserSession.CmrId, "from up", string.Empty, DateTime.Parse("2007-12-05 14:00"), DateTime.Parse("2007-12-05 16:00"), UserSession.UserId);

List<FPCalendarEvent> calList = FPCalendarEventFacad.GetCalenderEventListByCmrId(UserSession.CmrId, this.FPStartDate, this.FPEndDate);
BindCalendar(this.FPStartDate, calList, this.FPNumDays);

dpcCalendar.Update();
}


--------------------

I guess you already know my question =)
How can I update calendar after button inside the update panel is fired?
and the other way, I want to show some data about the event in the update panel when event is clicked in calendar.

I found a work around, I put the whole calendar inside the update panel and changed CallBack to PostBack.
That worked, but it's so much slower, when doing this, all action on all events are so much slower.

Can this be done on some other way? or maybe in a future release?
Comment posted by Jay
17 years ago.

Hi Jimmy,

I'm implementing a similar method where I put the calendar inside the updatepanel also, so I think I can shed some light on this.

After you do a click on the button inside the updatepanel, your page should automatically do a callback (that means you hit page load, and then maybe an event function like button_submit(){}). Inside the page load/ or in the button_submit function, you'll need to do an update on the calendar like this(in vb.net):

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

'you can add if conditions here
BindDPC(BegDate, EndDate)

End Sub

or

protectedsub BtnAdd_Click(byval sender as object , byvale as EventArgs)

'you can add if conditions here
BindDPC(BegDate, EndDate)
end sub

Inside this bindDPC function, you need to rebind the data, so something like this:

Private Sub BindDPC(ByVal CompID As Integer, ByVal OfficeID As Integer, ByVal BegDate As String, ByVal Enddate As String, ByVal StaffType As Integer)

Ds = objViewAppt.Loaddata(BegDate, Enddate)
DayPilotCalendar1.StartDate = BegDate
DayPilotCalendar1.DataSource = Ds
DayPilotCalendar1.DataStartField = "McDate"
DayPilotCalendar1.DataEndField = "McEndDate"
DayPilotCalendar1.DataTextField = "Title"
DayPilotCalendar1.DataValueField = "ID"
DayPilotCalendar1.DataBind()
DayPilotCalendar1.Update()
End Sub

The DayPilotCalendar1.Update() isn't necessary I believe, but I put it in there just to be safe. Once you do this, every time the button in the panel is clicked, you should come to the bindDPC function, and it'll reload the calendar for you this way. Hope that helped.

Comment posted by Jimmie Andersson
17 years ago.
Hi Jay, thank you for your answer.

Yes I understand what you meen and I've tried it, it works :)
But I found this way even before i posted my thread.

<i>I found a work around, I put the whole calendar inside the update panel and changed CallBack to PostBack.
That worked, but it's so much slower, when doing this, all action on all events are so much slower.</i>

As I said before, It works but the performance is so much slower, when the calendar is outside the update panel and i do something like a move or resize of an event, the update is way much faster, maybe thats because it doesnt need to send all html data to the browser again.
Comment posted by Dan Letecky
17 years ago.
Hi Jimmie,

First of all sorry for a late response.

There are two client-side methods that could be useful in this case:

refreshCallBack(startDate, days, customData)
This is fires a generic request for refresh. There are three optional arguments:
  • startDate - StartDate to switch to (accepts Date object, integer value that indicates days to be moved forwards or backwards, or null if no StartDate change is requested) - see http://www.daypilot.org/daypilot-pro-4.0.html for more details.
  • days - number of days to be visible
  • data - a custom string that is passed to the server-side event handler in RefreshEventArgs.Data property
This method doesn't actually do the changes, it passes the parameters to the server-side Refresh event where you can change the properties.

timeRangeSelectedCallBack(start, end, column)
This method could really help you: You need to pass the start and end dates of the new event. It fires the TimeRangeSelected event on the server side. If you add a new event to the database there and call DataBind() and Update() the control will be updated properly. See also http://www.daypilot.org/daypilotcalendar.calendar.timerangeselectedcallback.html

Let me know if this helped.
Comment posted by Jimmie
17 years ago.
Thanks for your answer, it helped :)

I solved it like this

client-side<asp:UpdatePanel ID="uplEdit" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="BtnAdd_Click" />
</ContentTemplate>
</asp:UpdatePanel>

<Daypilot:Daypilotcalendar
Id="dpcCalendar"
ClientObjectName="dpc1"
runat="server"
OnRefresh="DpcCalendar_Refresh"

... />


server-side
protected void BtnAdd_Click(object sender, EventArgs e)
{
//create new event or what ever
ScriptManager.RegisterClientScriptBlock(uplEdit, this.GetType(), "refresh", "javascript:dpc1.refreshCallBack();", true);
}


protected void DpcCalendar_Refresh(object sender, RefreshEventArgs e)
{
//Get new events and databind
dpcCalendar.Update();
}


workes very well, thanks!
This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.