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

Custom Error handling function not being invoked

10 Answers 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nick
Top achievements
Rank 1
Nick asked on 18 Feb 2010, 04:55 PM
Hi,

I'm trying to implement a custom client side error function for my grid so that I can effectively handle the time-outs from Forms Authentication.  I have a custom authorisation filter in my MVC app that handles unauthenticated AJAX calls and returns a 403 Forbidden status.

My view is as follows:

<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/SingleColumn.Master" Inherits="System.Web.Mvc.ViewPage" %> 
 
<asp:Content ID="cTitle" ContentPlaceHolderID="TitleContent" runat="server"
  Index 
</asp:Content> 
 
<asp:Content ID="cHeader" ContentPlaceHolderID="HeaderContent" runat="server"
</asp:Content> 
 
<asp:Content ID="cMain" ContentPlaceHolderID="MainContent" runat="server"
  <h1>Index</h1> 
  <
    Dim grid As Telerik.Web.Mvc.UI.Grid(Of PortalAudit) = Html.Telerik.Grid(Of PortalAudit) _ 
                                                              .Name("AuditGrid") _ 
                                                              .Ajax(Function(g) g.Action("AuditListing", "Audit")) _ 
                                                              .Pageable(Function(p) p.Total(CInt(ViewData("Total")))) _ 
                                                              .Sortable() _ 
                                                              .Filterable() _ 
                                                              .EnableCustomBinding(True) _ 
                                                              .ClientEvents(Function(events) events.OnError("onGridError")) 
    grid.Paging.PageSize = 20 
    Dim colUserName As New Telerik.Web.Mvc.UI.GridColumn(Of PortalAudit)(Function(a) a.UserName) 
    Dim colAction As New Telerik.Web.Mvc.UI.GridColumn(Of PortalAudit)(Function(a) a.Action) 
    Dim colController As New Telerik.Web.Mvc.UI.GridColumn(Of PortalAudit)(Function(a) a.Controller) 
    colController.Title = "Area" 
    Dim colAffectedEntity As New Telerik.Web.Mvc.UI.GridColumn(Of PortalAudit)(Function(a) a.AffectedEntity) 
    Dim colStatus As New Telerik.Web.Mvc.UI.GridColumn(Of PortalAudit)(Function(a) a.Status) 
    Dim colDescription As New Telerik.Web.Mvc.UI.GridColumn(Of PortalAudit)(Function(a) a.Description) 
    Dim colTimeStamp As New Telerik.Web.Mvc.UI.GridColumn(Of PortalAudit)(Function(a) a.DateStamp) 
    colTimeStamp.Title = "DateStamp" 
    colTimeStamp.Format = "{0:dd/MM/yyyy HH:mm}" 
    grid.Columns.Add(colUserName) 
    grid.Columns.Add(colController) 
    grid.Columns.Add(colAction) 
    grid.Columns.Add(colAffectedEntity) 
    grid.Columns.Add(colStatus) 
    grid.Columns.Add(colDescription) 
    grid.Columns.Add(colTimeStamp) 
    grid.Render() 
  %> 
</asp:Content> 
 
<asp:Content ID="cScript" ContentPlaceHolderID="ScriptContent" runat="server"
  <script type="text/javascript"
    function onGridError(e) { 
      alert("You have invoked the custom error function!"); 
      e.preventDefault(); 
      var xhr = e.XMLHttpRequest; 
      alert(xhr.status); 
      if (xhr.status == 403) { 
        alert("redirecting to login page"); 
        window.location = window.location; 
      } 
      else { 
        alert(e.textStatus); 
      } 
    } 
  </script> 
</asp:Content> 
 

The onError function is declared as explained in the help files but is not firing when the error is returned.  The default handling is firing and displaying the error in an alert box.

Have I declared the client event correctly?  Can you see why my custom function is not being called?

Thanks,
Nick

10 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 18 Feb 2010, 05:09 PM
Hello Nick,

Are you using the current official version 2009.3.1320? I just tested with that version and the error handler was correctly invoked. Do you see your custom message before the default one? Also check for any JavaScript errors.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Nick
Top achievements
Rank 1
answered on 18 Feb 2010, 05:34 PM
Hi Atanas,

Thanks for the swift reply.

Yes, I am using 2009.3.1320.  I don't see any alerts from my function at all. 

Firebug doesn't indicate any issues, I am however getting an error in the web developer console "no element found".

Any ideas?
0
Accepted
Atanas Korchev
Telerik team
answered on 19 Feb 2010, 07:46 AM
Hello Nick,

After further investigation I found what the problem was. To fix it please open telerik.grid.min.js and replace 'error.Grid' with 'errorGrid'.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Nick
Top achievements
Rank 1
answered on 19 Feb 2010, 10:19 AM
Spot on! 

Your support is awesome as always, thanks Atanas
0
Steven
Top achievements
Rank 1
answered on 26 Jul 2011, 02:32 PM
Hi Guys,

i have exactly the same problem! :( I'm using 2011.2.712...

My Javascript function:

function

 

 

onError(e) {

 

alert(

 

"Server error!");

 

}

My Grid:

 

ClientEvents(events => events.OnError(

 

"onError"));

Cheers,
Steve

 

0
Georgi Krustev
Telerik team
answered on 26 Jul 2011, 02:46 PM
Hello Steven,

 This is a known issue introduced in the Q2 2011 version of Telerik Extensions for ASP.NET MVC.
Please use the latest internal build uploaded in this forum.

Kind regards,
Georgi Krustev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Steven
Top achievements
Rank 1
answered on 27 Jul 2011, 10:26 AM
Hi Georgi,

thank you! Awesome, its working ;)

Best regards,
Steve
0
Emily Hatch
Top achievements
Rank 1
answered on 21 Feb 2012, 10:49 PM
Hi all,

I am experiencing this same problem using 2011.3.1115

<%= Html.Telerik().Grid<MyObject>()
        .Name("grdObjects")
        .Columns(columns => {
            columns.Bound(o => o.Title)
                   .Width(200);
            columns.Bound(o => o.Role);
        .DataBinding(dataBinding => dataBinding
            .Ajax()
            .Select<MyController>(c => c.GetObjectsFor(Model.Id)))
        .Pageable(p => p
            .PageSize(15)
            .Style(GridPagerStyles.NextPreviousAndInput))
        .Sortable()
        .Filterable()
        .ClientEvents(events => events.OnError("onAssignedError"))
        %>
 
<script type="text/javascript">
    function onAssignedError(e) {
        //Had more interesting handling here, but not firing so went basic
        alert('here');
    }
</script>

Any help would be greatly appreciated!

Thanks,
Emily
0
Petur Subev
Telerik team
answered on 22 Feb 2012, 09:23 AM
Hello Nick,

This problem is fixed in the latest version of the MVC extensions. Could you please upgrade and say if the problem persists ?

Regards,
Petur Subev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Jared
Top achievements
Rank 1
answered on 13 Mar 2012, 05:47 PM
I have 2011.3.1115 and noticed that I CAN make it work but while debugging a script error still occurs.

This is what I have for authorization:
protected override void OnAuthorization(AuthorizationContext filterContext)
{
    // Test authentication
    if (filterContext.HttpContext.Request.IsAuthenticated == false)
    {
        if (filterContext.HttpContext.Request.IsAjaxRequest() == true)
        {
            //filterContext.Result = new RedirectResult(Url.Action("LogOn", "Account", new { Area = "" }));
            var url = System.Web.Security.FormsAuthentication.LoginUrl + "?X-Requested-With=XMLHttpRequest";
            filterContext.Result = new RedirectResult(url);
        }
        else
        {
            filterContext.Result = new RedirectResult(Url.Action("LogOn", "Account", new {Area = ""}));
        }
    }
}

If I have a Grid with no custom onError client side event handling, I get the alert talking about JSON and the Grid hangs.

However if I create a client side onError event handler with the following:
function onError(e) {
  e.preventDefault();
  window.location = window.location;
}

The page does get redirected to the login page. If I'm debugging the application I still get a script error but at least there is no alert so it goes unnoticed to the user. I still think there is an issue, but for now this is a reasonable workaround for me at least.
Tags
Grid
Asked by
Nick
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Nick
Top achievements
Rank 1
Steven
Top achievements
Rank 1
Georgi Krustev
Telerik team
Emily Hatch
Top achievements
Rank 1
Petur Subev
Telerik team
Jared
Top achievements
Rank 1
Share this question
or