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; } }}
Ok, this works well:
<ig:WebDataMenu runat="server" ID="WebDataMenu1" IsContextMenu="true" OnItemClick="WebDataMenu1_ItemClick"> <AutoPostBackFlags ItemClick="On" ItemSelected="Off" /> <ClientEvents ItemClick="WebDataMenu1Client_ItemClick" />(but It makes the postback but I don't reach the handler in the server)
The problem is in the ItemSelected or ItemSelecting
<ig:WebDataMenu runat="server" ID="WebDataMenu1" IsContextMenu="true" OnItemSelected="WebDataMenu1_ItemSelected"> <AutoPostBackFlags ItemClick="Off" ItemSelected="On" /> <ClientEvents ItemSelected="WebDataMenu1Client_ItemSelected" />
or
<ClientEvents ItemSelecting="WebDataMenu1Client_ItemSelecting" />
The problem is that I can't unselect the item in js.
This code works for me (I don't like but It works)
In .aspx.cs:
protected void WebDataMenu1_ItemSelected(object sender, Infragistics.Web.UI.NavigationControls.DataMenuItemEventArgs e) { e.Item.Selected = false; }
In the .aspx: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; } }
}
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; } }}
<ig:WebDataMenu runat="server" ID="WebDataMenu1" IsContextMenu="true" OnItemSelected="WebDataMenu1_ItemSelected"> <AutoPostBackFlags ItemClick="Off" ItemSelected="On" /> <ClientEvents ItemClick="WebDataMenu1Client_ItemClick" ItemSelecting="WebDataMenu1Client_ItemSelecting"/> <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>
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; } } }
Hi joecuc,
Thank you for your reply.
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.
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.
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.
Please contact me if you need further assistance regarding this matter.