Ajax error handling

P

Programer

I use timer control which executes some code on server side event named
Timer1_Tick.
If user disconect internet connection, this page show error alert window. I
can not put try catch block in timer_thick event because it is server side
and internet connection is closed.

How to catch this error on client side?
 
R

Ratnesh Maurya

I use timer control which executes some code on server side event named
Timer1_Tick.
If user disconect internet connection, this page show error alert window. I
can not put try catch block in timer_thick event because it is server side
and internet connection is closed.

How to catch this error on client side?

Try this

try
{
//your code goes here
}
catch(err)
{ }

Cheers,
_Ratnesh
S7 Software
 
P

Programer

Sorry, but I need catch on client side. I need to catch ajax error which is
generated by ScriptManager.
How can I catch ScriptManager errors if my page is loaded and comp is
offline?
 
R

Ratnesh Maurya

Sorry, but I need catch on client side. I need to catch ajax error which is
generated by ScriptManager.
How can I catch ScriptManager errors if my page is loaded and comp is
offline?

that is client side javascript code.. :)

Regards,
-Ratnesh
 
C

Chris Taylor

Hi,

I am by no means an expert in this area, but one think that might work is to
handle the endRequest event on the client side PageRequestManager object.

This can be wired up using
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(MyEndRequestHandler).
Where MyRequestHandler is a JavaScript function that is called at the end of
a the async AJAX request, you could check for the error condition in this
function and handle it gracefully.

Hope this helps,
 
A

Arijit

Hi,

Chris Taylor was corect. anyway i am giving the complete code, add this in
your aspx or ascx file.

<script>

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

function EndRequestHandler(sender, args) {
if (args.get_error() != undefined) {
if ((args.get_response().get_statusCode() == '12007') ||
(args.get_response().get_statusCode() == '12029')) {
alert('Connection Problem');
args.set_errorHandled(true); //added so that the
error will not come
}
}
}
</script>



Thanks and Regards
Arijit Chatterjee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top