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

Context menu Javascript action

Asked by Elisa Bisello
16 years ago.
Hello, I've a problem: I want add an item in the context menu with javascript action, but I don't work:

<DayPilot:DayPilotCalendar ID="DayPilotCalendar1" ContextMenuID="DayPilotMenu1" ClientObjectName="dpc1" runat="server"
Days="1" TimeFormat="Clock24Hours" HeaderDateFormat="D"
DataValueField="key" DataTextField="subject" DataEndField="end" DataTagFields="tag" DataStartField="start" DataSource="<%# getData %>"
OnBeforeEventRender="DayPilotCalendar1_BeforeEventRender"
TimeRangeSelectedHandling="PostBack" OnTimeRangeSelected="DayPilotCalendar1_TimeRangeSelected" OnEventMenuClick="DayPilotCalendar1_EventMenuClick"
EventClickHandling="PostBack" OnEventClick="DayPilotCalendar1_EventClick"
HeaderClickHandling="PostBack" OnHeaderClick="DayPilotCalendar1_HeaderClick"
EventDeleteHandling="PostBack" OnEventDelete="DayPilotCalendar1_EventDelete" DurationBarColor="#666666">
</DayPilot:DayPilotCalendar>

<DayPilot:DayPilotMenu ID="DayPilotMenu1" ShowMenuTitle="true" MenuTitle="Appuntamento" runat="server">
<DayPilot:MenuItem Text="Modifica" Action="PostBack" Command="Modifica" />
<DayPilot:MenuItem Text="Duplica" Action="PostBack" Command="Duplica" />
<DayPilot:MenuItem Text="Cancella" Action="PostBack" Command="Cancella" />
<DayPilot:MenuItem Text="Cancella (Javascript)" Command="Cancella" Action="JavaScript" JavaScript="if (confirm('Do you really want to delete this event (' + e.text() + ')?'))dpc1.eventMenuClickCallBack(e, command);" />
</DayPilot:DayPilotMenu>

I fill example at this link http://www.daypilot.org/context-menu.html but I haven't understood like declaring the eventMenuClickCallBack...
I would want that to the event Javascript it made this:

protected void DayPilotCalendar1_EventMenuClick(object sender, DayPilot.Web.Ui.Events.EventMenuClickEventArgs e)
{
if (e.Command == "Modifica")
{
Response.Redirect("ModApp.aspx?key=" + e.Value + "&day=" + e.Start.ToString("d"));
//DayPilotCalendar1.DataBind();
}

if (e.Command == "Duplica")
{
DuplicaPlanner(e.Value);
DayPilotCalendar1.DataBind();
}

//cancella un evento
if (e.Command == "Cancella")
{
//Response.Write(e.Value);
CancellaPlanner(e.Value);

DayPilotCalendar1.DataBind();
}
}

Thanks.
Answer posted by Dan Letecky
16 years ago.
Since you are using a CallBack, you need to call DayPilotCalendar1.Update() after changing your data source (this is not necessary when using PostBack). By calling DayPilotCalendar1.Update() you tell the control to update the events on the client-side. The purpose of this method is to save bandwidth in cases when you don't perform any data source changes in the CallBack handler (if you don't call Update() it doesn't send the new event set back to the client).

Try this:

//cancella un evento
if (e.Command == "Cancella")
{
CancellaPlanner(e.Value);
DayPilotCalendar1.DataBind();
DayPilotCalendar1.Update();
}
Let me know if it's still not working.
Comment posted by Elisa Bisello
16 years ago.
I have tried your solutions, but nothing is changed.


protected void DayPilotCalendar1_EventMenuClick(object sender, DayPilot.Web.Ui.Events.EventMenuClickEventArgs e)
{

//cancella javascript un evento
if (e.Command == "Cancella2")
{
Response.Write(e.Value);
DayPilotCalendar1.DataBind();
DayPilotCalendar1.Update();
}
}

<DayPilot:DayPilotMenu ID="DayPilotMenu1" ShowMenuTitle="true" MenuTitle="Appuntamento" runat="server">
<DayPilot:MenuItem Text="Cancella (Javascript)" Command="Cancella2" Action="JavaScript" JavaScript="if (confirm('Do you really want to delete this event (' + e.text() + ')?'))dpc1.eventMenuClickCallBack(e, command);" />
</DayPilot:DayPilotMenu>

My problem could be that in my page I don't have Javascript script...I think that it's neccesary...right?
How I must write the script for executing the delete function?
Comment posted by Dan Letecky
16 years ago.
No additional JavaScript is necessary.

However, Response.Write() won't work in the CallBack event handler. It can only corrupt the callback HTTP response. If you want to test that it's really executed, set a breakpoint in the event handler and run your application in debug mode in Visual Studio (or you can log a message into a file on disk but remember to allow writing for the ASPNET account).
Comment posted by Elisa Bisello
16 years ago.
You have reason, following the debug it works correctly!

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