DayPilot Forums

DayPilot is the best open-source Outlook-like calendar control for ASP.NET.
DayPilot Pro Demo (Calendar control)
» DayPilot Pro live demo (Calendar control)
DayPilot Pro Demo (Scheduler control)
» DayPilot Pro live demo (Scheduler control)
Home » Features » How to delete / add Event via postback?

How to delete / add Event via postback?

Hi!

There are many examples that show how to fill the calendar with events initially. But how should I delete or add an event?
I prepared a ContextMenu for deleting like this:

<DayPilot:DayPilotMenu ID="DayPilotMenu1" runat="server">
<DayPilot:MenuItem NavigateUrl="javascript:alert('Deleting event (id {0})');" Target="" Text="Delete" Title="" />
</DayPilot:DayPilotMenu>

What should I write into the NaviageUrl?
Do I have to rebuild the whole page (e.g. NaviageUrl="MyCalendar.aspx?delete_id={0}) ?

The next question would be, if I have a button which produces a callback, can I then just simply add an event to the DataSource?

Could you maybe provide a complete example for this scenario on the demo page?

Thanks for your Help

Martin
Martin R. - 3/22/2007 12:35:33 PM
DayPilot 3.1 doesn't support AJAX callbacks so the best way would be to redirect to an URL and then reload the whole page. E.g.

1. Use NavigateUrl="MyCalendar.aspx?delete_id={0}"
2. In MyCalendar.aspx, detect QueryString["delete_id"] and delete the event in the database. Then call Response.Redirect("MyCalendar.aspx", true); to prevent the user to repeat this deleting action (by reloading the page).

However, this is only a temporary solution because DayPilot Pro 3.5 will support AJAX callbacks:

1. NavigateUrl="javascript:DayPilotCalendar1.DeleteEvent({0})"
2. On the server, handle EventDelete event. In DayPilotCalendar1_EventDelete, do the database update, call DayPilotCalendar.DataBind() and DayPilotCalendar.Update(). Then it updates the view on the client side.
3. In DayPilotCalendar1_EventDelete you will also have a chance to apply custom rules for deleting (and possibly deny the deleting action at all).

The syntax may change a little bit in final version of DayPilot Pro 3.5 but the principle will be the same. I will include it in the demos.
Dan Letecky - 3/22/2007 1:39:59 PM
Hi!

Using a page "reload" has the disadvantage that you lose the ViewState.

Using an AJAX-Call has another disadvantage, which is, that you can't access the controls of the page, as an AJAX-Call is a static function.

In my mind a normal PostBack which sends the EventID plus the Action (e.g. ContextEvent("23", "Delete") would be the best.

Any other way is not ASP.Net like in my mind. But I am no expert...
Martin R. - 3/26/2007 6:05:01 PM
Martin,

As we are discussing your scenario directly by e-mail, I'm not responding here. As soon as we finish the discussion I will post the options here so the others can benefit from it as well.
Dan Letecky - 3/28/2007 2:07:36 PM

<DayPilot:DayPilotMenu ID="DayPilotMenu1" runat="server"> <DayPilot:MenuItem NavigateUrl="javascript:alert('Deleting event (id {69157})');" Target="" Text="Delete" Title="" />add page</DayPilot:DayPilotMenu>

mamounamine@hotmail.com

mamounamine@hotmail.com - 6/27/2007 5:41:46 PM
Post reply