PageRequestManagerServerErrorException error when I press F5 while updatepanel is updating - asp.net

I have a updatepanel that is updated using timer every one second.
I also have async postback error handler set up in javascript as following:
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(onEndRequest);
function onEndRequest(sender, args) {
var error = args.get_error();
if (error != null) {
args.set_errorHandled(true);
alert(error.message);
}
}
when I refresh the page manually or click a hyperlink I get the following error in endRequest handler:
An unknown error occurred while processing the request on the server.
The status code returned from the server was: 0
How can i prevent this behavior?
Thanks

I figured it out.
For thoue who have the same problem, here is the code to determine if script manager async postback is currently running:
Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()
to cancel it call:
Sys.WebForms.PageRequestManager.getInstance().abortPostBack();
I just call the cancel method directly. It does not not anything when request is not running.

Related

Halt progress of Ninja Forms if Webhooks respond with error

I'm setting up Ninja Forms in Wordpress. And I want to use the Webhooks extension to post a code to an external URL. If the code is correct Ninja Forms should submit the data on move on. If the code is wrong then the user should get an error message and try again.
How can I do this, I see no way if interrupting the submit?
In Ninja Form when you use webhook, I guess you may catch the error respond from the API with this code
$data['errors']['form'][] = $this->submit_response->result[0]->error;
So when the API respond error, in this case user has no chance to re-submit the form again unless reload the page.
When the form contain the error, Ninja form prevent the form to submit, so you need to find a way to clear/remove this error.
Few workarounds can fix this problem.
An easy way is that, you cache the respond error differently with the following code:
$data['errors']['last']['message'] = $this->submit_response->result[0]->error;
With this code, your form will not display the error message respond from API but it is possible for user to re-submit the form again and you can use the javascript code below to display the error to some HTML element
var customFormController = Marionette.Object.extend({
initialize: function() {
// Listen to submit respond
this.listenTo(nfRadio.channel( 'forms' ), 'submit:response', this.checkSubmitRespond);
},
checkSubmitRespond: function(response, textStatus, jqXHR, formID) {
if ('undefined' != typeof response.errors.last) {
var msg = response.errors.last.message;
// display error on some pre-defined element
jQuery('.error-container').html(msg);
}
}
});
jQuery(document).ready(function($) {
new customFormController();
});
Hope this help.

Update panel, end request handler, no error object?

All,
When I upgraded from asp.net 2.0 to asp.net 3.5 and now in my custom end request handler, the args.get_error() returns null (I traced it all the way to function Sys$WebForms$PageRequestManager$_endPostBack(error, response), the error object is null there too). This happens on my production server, on my development machine it works, I get the error object.
Both are win 7 machines, IIS 7.5.
FYI: On the server, I log the error, and clear it via ctx.Server.ClearError();
Then I set the AsyncPostBackErrorMessage on the script manager.
**UPDATE:
By setting AllowCustomErrorsRedirect="false" on the ScriptManager explicitly resolves the issue. **
Found this on MSDN little explanation:
https://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.allowcustomerrorsredirect(v=vs.110).aspx
Remarks
The AsyncPostBackError event is raised when there is a page error during asynchronous postbacks. How errors on the server are sent to the client depends on the AllowCustomErrorsRedirect property, the AsyncPostBackErrorMessage property, and the custom errors section of the Web.config file.
Here's client script code for handling ajax errors:
mgr.add_beginRequest(function(sender, args) {
postBackElem = args.get_postBackElement();
if (typeof(postBackElem) === 'undefined')
return;
targetPnl = self.getTargetPnl(mgr, postBackElem);
$(targetPnl).addClass('updateprogress-started', duration);
}); //beginRequest
mgr.add_endRequest(function(sender, args) {
if (typeof(postBackElem) === 'undefined')
return;
$(targetPnl).removeClass('updateprogress-started', duration);
if (args.get_error() != undefined){
var msg;
if (args.get_response().get_statusCode() == '200') {
msg = args.get_error().message.replace("Sys.WebForms.PageRequestManagerServerErrorException: ", "");
}
else {
msg = 'An unspecified error occurred.'; // error occurred somewhere other than the server page
}
args.set_errorHandled(true); // show error in our custom panel
$(self._errText).text(msg);
$(self._errPanel).show();
}
}); //endRequest
By setting AllowCustomErrorsRedirect="false" on the ScriptManager explicitly resolves the issue.

Timeout Errors on an UpdatePanel skip Appliation_Error - how do I capture them?

Working with some legacy code that has a great many UpdatePanels. We are experiencing problems where some postbacks to UpdatePanels are timing out (exceeding the default 90 second limit), and I want to know when this happens.
We are currently logging all unhandled exceptions in Global.asax.cs::Application_Error. If I manually throw in an error in a postback on the update panel, this is captured just fine. If I drop in a Thread.Sleep(100 * 1000), I will not see anything in Application_Error, but on the client I will see:
Uncaught Sys.WebForms.PageRequestManagerServerErrorException:
Sys.WebForms.PageRequestManagerServerErrorException:
An unknown error occurred while processing the request on the server.
The status code returned from the server was: 500
From what I can tell, it is the server layer throwing the error, not the application itself, and so we will never see anything hit Application_Error. Is that correct?
Also, are there any options for actually capturing/logging this error, aside from noticing it in the client, and then doing another POST operation back to log it?
You have two approaches that I know of:
Server-side:
protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
ScriptManager1.AsyncPostBackErrorMessage = "An error occurred during the request: " + e.Exception.Message;
}
Client-side:
<script type="text/javascript">
// Subscribe to the end request event of the update panel
function pageLoad() {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(onEndRequest);
}
// You can of course have this emit the error information to whatever control you want, I made up the Label1 object for demonstration purposes
function onEndRequest(sender, args) {
var lbl = document.getElementById("Label1");
lbl.innerHTML = args.get_error().message;
args.set_errorHandled(true);
}
</script>
Here is some documentation:
Customizing Error Handling for ASP.NET UpdatePanel Controls
Error Handling Customization for ASP.NET UpdatePanel

In Meteor, what is difference between this.error and throw new Meteor.Error in Meteor.publish?

In Meteor.publish, what is a difference between using this.error and simply throwing an Meteor.Error?
this.error is only available inside the publish method. Per the docs:
Stops this client's subscription, triggering a call on the client to the onError callback passed to Meteor.subscribe, if any. If error is not a Meteor.Error, it will be mapped to Meteor.Error(500, "Internal server error").
Throwing a Meteor.Error would not stop the client's subscription, it would just terminate execution and raise the exception. So if you want to ensure Meteor will clean up after you and allow you to handle the error on the client when something unexpected happens, it's recommended to use this.error rather than throwing your own inside the publish method.
It seems they are the same. In the source code:
try {
var res = self._handler.apply(self, EJSON.clone(self._params));
} catch (e) {
self.error(e);
return;
}
So if there is an exception thrown, error is called anyway. error also stops the subscription.

Data not being sent to the server through web method?

I use PageMethods to return parameters from the client-side to the server-side. Something like this:
if (/*node has no kids*/) {
PageMethods.ApplicationInfo(node.data.key, node.data.title, onSuccess, onFailed);
<%=Page.ClientScript.GetPostBackEventReference(this, "MyCustomArgument") %>
}
else {
PageMethods.ApplicationInfo(0, "", onSuccess, onFailed);
}
My web method:
[WebMethod(EnableSession = true)]
public static void ApplicationInfo(int appId, string appDescr)
{
curAppId = appId;
curAppDescription = appDescr;
}
As you can see, I invoke a postback if the condition is true.
So, the problem is the web method runs smoothly and ends in onSuccess function in the 'else' condition, but gives me the 'server method failed' error otherwise.
What can cause it? Thanks a lot in advance!
EDIT
Ok problem changed.
I moved the postback to the onSuccess function, and stopped getting the mistake.
Locally, everything works fine, but the data which I pass to ApplicationInfo somehow are not passed, when I try to launch the site from the server.
What can be the problem?

Resources