This is a migrated thread and some comments may be shown as answers.

Cancel Webservice call on menu close

1 Answer 37 Views
Menu
This is a migrated thread and some comments may be shown as answers.
MFitzpatrick
Top achievements
Rank 1
MFitzpatrick asked on 14 Apr 2011, 08:47 PM
I am using the following RadContextMenu in conjunction with a radgrid

<telerik:RadContextMenu ID="grdContextMenu" runat="server"
     EnableRoundedCorners="true" EnableShadows="true" OnClientItemPopulating="FetchUserList_Pre"
     EnableAutoScroll="true"
     OnClientItemPopulationFailed="ServiceFailure"
     >
     <WebServiceSettings Path="../Services/TimeSchedule.asmx" Method="FetchUserList"  />
     <LoadingStatusTemplate>
         <div style="padding-top:100px;text-align:right;width:120px;float:left;">
             <asp:Image runat="server" ID="LoadingImage" ImageUrl="../Images/Working.gif" ToolTip="Loading..."
                 Width="50px" Height="50px" />
                 <br />
                 Loading Users...
         </span>
     </LoadingStatusTemplate>
     <Items>
          
         <telerik:RadMenuItem Text="Add" ToolTip="Add a new record" />
         <telerik:RadMenuItem Text="Delete"   ToolTip="Delete this record"/>
         <telerik:RadMenuItem Text="Copy To Day" ToolTip="Copy this shift to the selected day"
              GroupSettings-Height="165" GroupSettings-ExpandDirection="Auto" >
              
             <Items>
                 <telerik:RadMenuItem Text="Sunday" Value="Sunday"></telerik:RadMenuItem>
                 <telerik:RadMenuItem Text="Monday" Value="Monday"></telerik:RadMenuItem>
                 <telerik:RadMenuItem Text="Tuesday" Value="Tuesday"></telerik:RadMenuItem>
                 <telerik:RadMenuItem Text="Wednesday" Value="Wednesday"></telerik:RadMenuItem>
                 <telerik:RadMenuItem Text="Thursday" Value="Thursday"></telerik:RadMenuItem>
                 <telerik:RadMenuItem Text="Friday" Value="Friday"></telerik:RadMenuItem>
                 <telerik:RadMenuItem Text="Saturday" Value="Saturday"></telerik:RadMenuItem>
                  
             </Items>   
         </telerik:RadMenuItem>
         <telerik:RadMenuItem Text="Copy Shift (Open)"  ToolTip="Copy this shift as open or to another user"
          GroupSettings-Height="250" GroupSettings-Width="200"  GroupSettings-ExpandDirection="Auto"  ExpandMode="WebService"
         >
         </telerik:RadMenuItem>
          
          
     </Items>
 </telerik:RadContextMenu>


As you can see I am using a web service call to populate the menu items of a submenu when I right click on one of the grid rows. This works perfectly.

However, I have run into a problem. The service call at times can take a second or two. That is not really an issue. However, if I select to expand the menu item that is populated using the web service (thus initializing the web call), then click a different menu item (which performs a partial postback) before the web service populates the menu, I get the following error:  'this.get_element()' is null or not an object.

I am guessing that the callback function for the webservice is looking for the radmenu and not finding it, because a postback has occurred. Using the OnClientItemPopulationFailed to suppress the error does not work. I would like to cancel the service call in the OnClientItemClosing event. Does anyone have any idea how to get an instance of the web call and abort it?

Thanks
 

1 Answer, 1 is accepted

Sort by
0
MFitzpatrick
Top achievements
Rank 1
answered on 18 Apr 2011, 04:35 PM
I figured this out.

If anyone else has this problem, you can abort the service call in the onClientMenuClosing or Closed handler with the following code. This will also work if the request abort is called in the OnClientItemPopulationFailed handler.

/// This aborts the service call for the FetchUserList if the menu closes before
/// the service call returns the user list
function MenuItemClosed(sender, eventArgs) {
 
    var mnu = eventArgs.get_item(); // get closing menu
    var selIndex = mnu.get_index(); // get closing menu index
    if (selIndex == 3) {            // if matches the menu that calls web service
        if (sender._webServiceLoader) {
            if (sender._webServiceLoader._currentRequest) {
                sender._webServiceLoader._currentRequest._executor.abort(); // abort service call
 
            }
        }
    }
}
This could probably be added to future versions so that any outstanding web service call is aborted if any menu item performs a partial postback or raises a non-related client event.

Thanks

Mike
Tags
Menu
Asked by
MFitzpatrick
Top achievements
Rank 1
Answers by
MFitzpatrick
Top achievements
Rank 1
Share this question
or