Hello, I've a problem with the cancel event in the WebDataMenu.I've a WebDataMenu as a context menu in a WebDataTree. In some of the menu items I want to make actions in client. In other items I want to execute the server handler.With the server action there is no problem, but if I cancel the postback once, the client handler doesn't work for this item any more.
You can try this sample:
The first time I click in the first item I see the message, but if I click again it doesn't work, if I click in the second item there is no problem.
<ig:WebDataMenu runat="server" ID="WebDataMenu1" IsContextMenu="true" Style="display: none;" OnItemSelected="WebDataMenu1_ItemSelected"> <AutoPostBackFlags ItemClick="Off" ItemSelected="On" /> <ClientEvents ItemSelected="WebDataMenu1Client_ItemClick" /> <GroupSettings AnimationType="ExpandAnimation" Orientation="Vertical" /> <Items> <ig:DataMenuItem Text="No Postback" Key="Np"> </ig:DataMenuItem> <ig:DataMenuItem Text="Postback" Key="Yp"> </ig:DataMenuItem> </Items> </ig:WebDataMenu>
function WebDataMenu1Client_ItemClick(sender, e) { var itemMenu = e.getItem(); switch (itemMenu.get_key()) { case "Np": { alert("No Postback"); e.set_cancel(true); break; } case "Yp": { alert("Yes, Postback!"); e.set_cancel(false); break; } }}
Hi joecuc,
Please contact me if you need further assistance regarding this matter.
Thank you for your reply.
I have further investigated the sample you have provided and it appears to be working as intended. Please note that the Selection client-side behaviors are fired before the ItemClick events. After canceling an item selection, the selection events should no longer be fired for the same item upon consecutive mouse clicks until another item has been selected/clicked. This is the default behavior of WebDataMenu. I would therefore suggest that you move the logic for your no postback item in the ItemClicked event.
Please let me know if you have any questions.
No, it doesn't work for me.
If you execute the "No postback" item, First time you handle "ItemSelecting" & "ItemClick", if you click again you can handle only "Itemclick". You can't execute the "ItemSelecting" handler never more...
The item is not active or selected but I can't execute the itemSelecting again.
I'd try to do a WebDataMenu1.Initialize() before the ShowAt(... but this function don't clean the handlers and executes the itemSelecting & ItemClick several times.
You can deselect the currently selected WebDataMenu item using the following javascript code:
ig_controls.WebDataMenu1.get_selectedItem().set_selected(false)
Please let me know if this helps.
Yes, could I unselect the node in client?
Because I can't do a conditional postback.
In this sample I want to make the postback at second time that I click in the third menu option...
var times=0; function WebDataMenu1Client_ItemSelecting(sender, e) { var itemMenu = e.getItem(); switch (itemMenu.get_key()) { case "Np": { // itemMenu.set_selected(false); e.set_cancel(true); break; } case "Yp": { //actions before postback alert("Yes, Postback (Selecting)"); break; } case "Cp": { alert("Conditional Postback (Selecting)"); if (times < 2) e.set_cancel(true); times += 1; break; } }
}
function WebDataMenu1Client_ItemClick(sender, e) { var itemMenu = e.getItem(); switch (itemMenu.get_key()) { case "Np": { //actions in client alert("No Postback (Click)"); break; } case "Yp": { break; } case "Cp": { alert("Conditional Postback (Click)"); e.getItem().get_previousItem().set_selected(true); break; } } }