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

Menu - Javascript commandCallBack is executed after page.loadcomplete and causes page to stop rendering

Asked by John H
12 years ago.

Hi,

I have a scheduler control with a context menu like so:

<DayPilot:DayPilotMenu ID="DayPilotMenu1" runat="server" CssClassPrefix="menu_">
<DayPilot:MenuItem Text="Send" Action="JavaScript" JavaScript="dps1.eventMenuClickCallBack(e, command);">
</DayPilot:MenuItem>
<DayPilot:MenuItem Text="Refresh" Action="Postback" Command="Refresh">
</DayPilot:MenuItem>
</DayPilot:DayPilotMenu>

I would expect both the send and refresh commands to work similarly and call the server-side DayPilotScheduler1.EventClick routine. However EventClick fires at a different point in the asp.net lifecycle in each case and this causes problems with rendering. Using debugging I can see that the 'Refresh' command (using a normal postback) causes the EventClick handler to fire, followed by Page.LoadComplete and then Page.PreRender. However, the 'Send' command (using javascript to create a postback) fires Page.LoadComplete followed by EventClick. At this point the asp.net page seems to skip the rest of the lifecycle, and Page.PreRender never fires. Other controls on the page also reach the PreRender stage.

I discovered this when trying to create a 'delete' command in a context menu. Because I wanted the user to confirm the action I used:

<DayPilot:MenuItem Action="JavaScript" Command="Delete" Text="Delete" JavaScript="if (confirm('Delete ' + e.text() + '?')) dps1.eventMenuClickCallBack(e, command);" >
</DayPilot:MenuItem>

In the EventClick handler I was rebinding a gridview also on the page so that it would reflect the fact that a record had been deleted (using GridView1.Databind()). Databind was successfully called and I could see that there was one fewer row bound to the grid, but as the asp.net page stopped processing before re-rendering controls the gridview still showed the old deleted row.

Hope this makes sense - I've been tying myself in knots with this all day. This may be one of the many things I don't understand about asp.net.

Answer posted by John H
12 years ago.

Ah I've solved it - sorry, my mistake.

I wasn't thinking about the difference between callback and postback - replacing eventMenuClickCallBack with eventMenuClickPostBack makes it work.

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