0

When deleting a row in jqgrid, I would like to return a custom error text when server returns 500 error. I am using jqGrid for ASP.NET, and the grid does not seem to have an "loadError" event

Has anyone done this?

jqGrid is defined like this

<trirand:JQGrid runat="server" ID="Jqgrid" ShrinkToFit="true" Width="900px" Height="500" PagerSettings-PageSize="20" PagerSettings-PageSizeOptions="[20,50,100]" OnSearching="JQGrid_Searching" OnSorting="JQGrid_Sorting" OnRowEditing="JQGrid_RowEditing" OnRowDeleting="JQGrid_RowDeleting">
                    <Columns>
                        <trirand:JQGridColumn DataField="ID" PrimaryKey="True" Width="40" Visible="False" />
                        <trirand:JQGridColumn DataField="NAME" SearchType="DropDown" Width="55" SearchControlID="ddlNameFilter"
                            HeaderText="Name" Editable="true">
                            <EditClientSideValidators>
                                <trirand:RequiredValidator />
                            </EditClientSideValidators>
                        </trirand:JQGridColumn>
                        <trirand:JQGridColumn DataField="DESCR" SearchType="DropDown" Width="55" SearchControlID="ddlDescrFilter"
                            Searchable="True" HeaderText="Descr" Editable="true">
                            <EditClientSideValidators>
                                <trirand:RequiredValidator />
                            </EditClientSideValidators>
                        </trirand:JQGridColumn>
                        <trirand:JQGridColumn HeaderText=" " EditActionIconsColumn="true" Width="50" EditActionIconsEditEnabled="false"
                            CssClass="clickable" />
                    </Columns>
                    <ClientSideEvents LoadComplete="loadComplete" ColumnSort="columnSort" RowDoubleClick="editRow">
                    </ClientSideEvents>
                    <ToolBarSettings ShowSearchToolBar="True" ToolBarPosition="TopAndBottom">
                    </ToolBarSettings>
                    <PagerSettings NoRowsMessage="No rows to display" />
                    <ExportSettings ExportDataRange="All" />
                </trirand:JQGrid>
camillajac
  • 55
  • 5

1 Answers1

2

The callback loadError are used to process errors during filling/loading of the grid. Form editing methods like delGridRow supports errorTextFormat callback. So is you use navGrid you should define errorTextFormat callback as the method of prmDel parameter of navGrid.

Additionally I would recommend you to use [HandleJsonException] instead of [HandleError] in case of usage ASP.NET MVC (see the answer for details). In other ASP.NET applications you can define the error handler Application_Error in Global.asax.cs (see the answer). The usage of such handles will simplify you the analyse of the error server response inside of errorTextFormat callback because the error information will be returned as JSON.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I have tried $.extend($.jgrid.del, { errorTextFormat: changeTextFormat }); But can't get it to work :( – camillajac Jun 29 '12 at 06:24
  • @user1488446: What is not work exactly? Is the method `changeTextFormat` be called? Do you tried just the following `$.extend($.jgrid.del, { errorTextFormat: function(response) {alert("My Custom error: " + response.statusText);}});`? – Oleg Jun 29 '12 at 07:19
  • Hi, this is working if I don't have a try/catch in the deletefunction in codebehind. I want to display my catch errormessage. Is this possible? – camillajac Jun 29 '12 at 08:51
  • @user1488446: Sorry, but I don't understand what you mean. The `errorTextFormat` will be called if the response from the server has any *error HTTP status code*. In case of all unhandled exceptions it will be done automatically. You can set manually. For example `Response.StatusCode = (int)HttpStatusCode.InternalServerError;`. Alternatively you can just throw new exception inside of `catch`. – Oleg Jun 29 '12 at 08:58