aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Show Asp.Net Exception Error Message in AJAX Call Error Function in C#.Net VB.Net

May 17, 2015

Here I will explain how to show exception error message in jQuery ajax web method calls using error function in c#, or get error message in jQuery ajax post method in using c#, with example or jQuery show custom error message during ajax calls in using c#,

Now create one new web application and open your aspx page and write the code like as shown below

<html xmlns="">
<head runat="server">
<title>jQuery Get Original Exception Message in Ajax Method</title>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(function () {
$('#btnSum').click(function () {
var val1 = $.trim($('#txtVal1').val());
var val2 = $.trim($('#txtVal2').val());
type: "POST",
url: "GetExceptionMessageinjQuery.aspx/GetSumofNumbers",
data: "{'val1':'" + val1 + "', 'val2':'" + val2 + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
error: function (data) {
var r = jQuery.parseJSON(data.responseText);
var errorMessage = r.Message;
var exceptionType = r.ExceptionType;
var stackTrace = r.StackTrace;
$('#divStatus').html("<b>Error Message: </b>" + errorMessage + "</br></br>" + "<b>ExceptionType: </b>" + exceptionType + "</br></br>" + "<b>Asp.Net StackTrace: </b>" + stackTrace)
return false;
<form id="form1" runat="server">
<tr><td>First Number:</td><td><input type="text" id="txtVal1" /></td></tr>
<tr><td>Second Number:</td><td><input type="text" id="txtVal2" /> </td></tr>
<tr><td>SUM:</td><td><label id="lblMessage"/></td></tr>
<tr><td colspan="2"><input type="button" id="btnSum" value="Get Sum" /></td></tr>
<hr />
<div id="divStatus"></div>

Now open aspx page codebehind behind file and add following namespaces

C# Code

using System;
using System.Web.Services;

After completion of adding namespaces you need to write the code like as shown below

protected void Page_Load(object sender, EventArgs e)

public static int GetSumofNumbers(int val1, int val2)
return val1 + val2;


Imports System.Web.Services
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

End Sub
<WebMethod()> _
Public Shared Function GetSumofNumbers(ByVal val1 As Integer, ByVal val2 As Integer) As Integer
Return val1 + val2
End Function
End Class


jQuery Show Asp.Net Exception Error Message in AJAX Call Error Function in C#.Net VB.Net

Download Sample Code Attached

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.