XGrid with Contextmenu does not work in Ajax Updatepanel

Nov 7, 2007 at 12:20 PM
Well I have tried to use XGrid with context menu in ajax update panel. Almost everything works fine but if click on context menu it alwas made a postback rather than an ajax call? any idea????
Jan 24, 2008 at 1:34 PM
same problem.
Feb 28, 2008 at 9:12 PM

Hello farukh and murtola - I posted what I think is a fix:

I'm no AJAX expert, but I was really frustrated the context menu wasn't working with AJAX - so I played with it until I came up with what I think is a fix. I have not tested this much, so please test it or adjust the script as necessary. I'd have to say this is "use at your own risk" - but it seems to work for what I need!

I had two problems while trying to use the xgrid and context menu in an update panel:

1. When using the IDE and editing the properties of the xgrid in the properties window, when you selected the contextmenu name in the "contextmenuid" field, it would replace the clientid name with the uniqueid. In otherwords, if your context menu was named contextmenu1 it would put in "ctl04_contextmenu1" or something like that. Well I stepped through the debugger and found that it wasn't finding the control because it needed to find the clientid and NOT the uniqueid.... So, I tried editing the "contextmenuid" property in the source of the .aspx file and it worked! Simply open the source of the .aspx file, go to the xgrid element and add contextmenuid="contextmenu1" to the element properties and then compile and run the page. This is a bit of a hack, but for the life of me I could not find the location in the contextmenu code that kept changing the contextmenuid property while in design mode.... if you figure this out, please let me know! NOTE: I don't know if this works when you ARE NOT USING THE GRID IN AJAX UPDATE PANEL!!!! I didn't test that.

2. When using the context menu in an update panel, if you clicked on a menu item, it would post back the whole page, rather than doing an async callback for partial rendering.... but I debugged this problem and came up with the following fix:

Download the source code for xGrid and open the project. Then open the ContextMenu.cs class file. Goto what was line 256 for me - you should see code like:

// Added by Bilal Haidar
button.OnClientClick = item.OnClientClick;

button.CommandName = item.CommandName;
}

Simply insert the following code directly after the "button.CommandName = item.CommandName;" line.... like so:

// Added by Bilal Haidar
button.OnClientClick = item.OnClientClick;

button.CommandName = item.CommandName;

//register with async callback if scriptmanager is present
if (ScriptManager.GetCurrent(this.Page) != null)
{
ScriptManager.GetCurrent(this.Page).RegisterAsyncPostBackControl(button);
}
}

Recompile and go. You should now see the "itemcommand" event firing in AJAX!

Hope this helps someone!
Aug 14, 2008 at 6:11 PM
I have tried to use the above solution

//register with async callback if scriptmanager is present

 

//this handles context menu in update panel

 

 

if (ScriptManager.GetCurrent(this.Page) != null)

 

{

ScriptManager.GetCurrent(

this.Page).RegisterAsyncPostBackControl(button);

 

}

But I get error on SrciptManager
ScriptManager does not exit in current context

also How do I add the above source Code in my existing Web site