Spread 9 with MVC - show error message from server

Posted by: Javier.Rapoport on 3 November 2017, 1:45 am EST

    • Post Options:
    • Link

    Posted 3 November 2017, 1:45 am EST

    Hello. I am trying to add error handling for server-side exceptions to our callbacks, but I cannot seem to return a message to the UI.

    I am setting “e.Handled = true;” so that the CallBackStopped event is fired on the client side, but I cannot find how to send an error message. Can someon please let me know how to do this?

    We are using: C#, MVC3, Spread 9.4

    JavaScript:

    
    sheet.UpdatePostbackData(); 
    sheet.CallBack('Export', true); 
    
    

    and

    
            $('#sheet').bind('CallBackStopped', function (event) {
                // how display error from server here?
            });
    
    

    C# controller action:

    
    protected void ButtonCommand(object sender, SpreadCommandEventArgs e, SheetCommands shtCmds)
    {
    	FpSpread spread = (FpSpread)sender;
    
    	if (e.CommandName.Equals("Export"))
    	{
    		try
    		{
    			ExportSheet();
    		}
    		catch (Exception ex)
    		{
    			e.Handled = true;
    			// How can I return an error message to the UI?
    		}
    	}
    }
    
    
  • Posted 7 November 2017, 1:39 am EST

    Hello,

    You can simply add a message to the ViewBag in controller and show it in the CallBackStopped event client side( in View).

    Something like:

    
    protected void ButtonCommand(object sender, SpreadCommandEventArgs e, SheetCommands shtCmds)
    {
    	FpSpread spread = (FpSpread)sender;
    
    	if (e.CommandName.Equals("Export"))
    	{
    		try
    		{
    			ExportSheet();
    		}
    		catch (Exception ex)
    		{
    			e.Handled = true;
    			  ViewBag.Message = "Error Message!";
    		}
    	}
    }
    
    $('#sheet').bind('CallBackStopped', function (event) {
                alert('<%=ViewBag.Message%>');
            });
    
    

    I hope it helps.

    Thanks,

    Deepak Sharma

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels