I posted for some help over here:
Avoiding try/catch hell in my web pages
I have added an 'override OnError' in a common base class from all my pages, and can confirm that it works properly by putting a breakpoint within the function. However, I still get an exception propagating to the client, no matter what I do. Here is my issue:
1) I have a Telerik Grid control that is updated based on the value of a ComboBox. If an exception occurs and I catch it in a try/catch block then everything is fine.
2) If I get an exception when the ComboBox is changed but there is NO use of a try/catch block, then the error is caught in OnError. However, now I get a PageRequestManagerServerErrorException error just popping up in the client Ajax response (Javacript).
Any help?
There could be many reasons why it's happening. For one, it could be something with client-side rendering that's causing it, or it could be an AJAX request from an update panel or the RadAjaxPanel... one way to possibly tell is to tap into the Sys.WebForms.PageRequestManager's endRequest event, which is discussed briefly here: http://encosia.com/2007/07/18/how-to-improve-aspnet-ajax-error-handling/
So the error is possibly not happening around that area of code that has the try/catch block, but could be caused from something internal in the Telerik processes...
Could you share any code/markup?
Thanks.
Related
I don't really know where to start with this one. I am getting:
`Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.`
after moving a website to a new server. The exact same code works on my other server. It happens when I submit one of my forms (but doesn't do it on all form submissions).
Any ideas what can cause this so I have somewhere to look?
Using: ASP.NET 2.
EDIT: I am adding some user controls to a placeholder dynamically at runtime but this same code is working ok on my other server. I have tried clearing the controls in the place holder before adding new ones (as I saw a post about that) but it hasn't helped.
EDIT2: It seems that the postback is just failing. It isn't going into the onClick code of the button either so something is deffintiely screwy .. If I try / catch the exception it seems that all the controls are still added successfully ... Setting my Dynamic UC's to EnableViewState = false resolves this particular error.
EDIT3: Ok, I think I may have a handle on what is happening. For some reason on the old server the form action is default.aspx?action=amend but the new server is showing amend.html?action=amend so I think the re-write module is messing up in IIS. This would explain the control adding issue as well because the action is happening 2 times (I think). I will look into the Rewrite module and see if anything is wrong then post back.
Please, have a look at these articles:
http://blog.typps.com/2008/01/failed-to-load-viewstate-typical.html
http://weblogs.asp.net/guys/archive/2004/12/05/275321.aspx
Or try a simple temporary solution - disable viewstate for this placeholder. Either way, I'm puzzled why it actually works on your first server. I'd be glad if someone else will be able to clarify this subject more.
It turns out that the post back Url for the form is wrong on this server (unsure why at the moment, I will update when I know). This is causing the dynamic controls to be added in an unexpected way and causing the error. I noticed this when I managed to post my form and the content didn't update. I manually adjusted the action url using firebug and all is well.
Worth looking at walther's answer regarding dynamic controls and the viewstate though.
Not sure what caused it but I am manually setting the form action in the page load now and it seems to have solved the issue.
I have an ASP.net page with two web methods. Everything worked fine until I tried to add an ASP.net UpdatePanel. The UpdatePanel works, but now I can't call my web methods. They fail and return the following error: "Message":" is not a valid valid for Int16..."
I can place a breakpoint on the first line of my web method and it won't be hit; so that tells me something about where the error is coming from.
Anyhow, is it practical to use web methods and UpdatePanels on the same page?
Okay, I must apologize to those who have read my question so far. I discovered a subtle bug that I introduced into my code at the same time I added the ASP.net UpdatePanel.
Normally, I would just delete my question, but since the question has not been previously asked, I'm going to answer my own question:
Yes it's possible to use both UpdatePanel and WebMethod within the same page
... for anyone else who wants to know.
i have just noticed something strange in some asp.net markup.
I have a standard form with a couple of textboxes and a submit button.
When clicked the code behind will attempt to perform some logic and then return.
If the input values are not valid it used to throw an exception.
The moment i wrapped the controls in an AJAX update panel and try to submit bad data, no exception is thrown and the panel returns like nothing was wrong.
Does anyone know how to return this to the previous behavior whilst keeping the update panel?
The expression it is thrown, but its handle by ajax, and now have be come Javascript errors, because now the full page is not loaded, but the error return back from javascript ajax call.
To see them just open your javascript error console :), how ever you do not need the expression as Raj say, you need to find other way to show your errors.
When I won to make some test and find my error, I remove the Ajax Panel for this reason, locate the error, fix them, then place back the Ajax Panel
This one is a little... odd. Basically I have a form I'm building using ASP.NET Dynamic Data, which is going to utilize several custom field templates.
I've just added another field to the FormView, with it's own custom template, and the form is loading that control twice for no apparent reason. Worse yet, the first time it loads the template, the Row is not ready yet and I get the error message:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control
I'm accessing the Row variable in a LinqDataSource OnSelected event in order to get the child object...
Now for the wierd part: If I reorder the fields a little, the one causing the problem no longer gets loaded twice.
Any thoughts?
EDIT: I've noticed that Page_Load gets called on the first load (when Row throws an exception if you try to use it) but does NOT get called the second time around. If that helps any...
Right now managing it by just catching and ignoring the exception, but still a little worried that things will break if I don't find the real cause.
EDIT 2: I've traced the problem to using FindControl recursively to find other controls on the page. Apparently FindControl can cause the page lifecycle events (at least up to page_load) to fire... and this occurs before that page "should" be loading so it's dynamic data "stuff" isn't ready yet.
You aren't referring to something in Page_Load that is set in OnSelected, are you? Something like your row object. OnSelected is a postback event and occurs after Page_Load. It's the only thing I can think of that might cause your exception when the row is not ready.
Start commenting things out in your code behind until either everything is commented or your control no longer loads twice.
If it is still doing it, start unhooking things in the control itself. Eventually, you'll get to the actual issue.
This is perhaps related to this question, but I have slightly more information.
I recently updated an ASP.Net application to .NET 3.5 after coding a few new pieces with Linq. Now my pages intermittently stop firing event handlers. I have it narrowed down to pages with Ajax on them, and I assume it's either the ScriptManager or the AjaxControlToolkit registration that is precipitating the problem.
The really screwy part is that pages seem to work fine about 2/3s of the time, and the controls lose their event handlers only 1/3 of the time. I wondered about some type of error occurring and the page not rendering correctly, but I cannot find evidence of this.
We were have exactly this issue and as you have said it was only happening some of the time and only on pages with Ajax requests. We found that disabling the HTTP Keep-Alive as suggested in the answer to
Why does Internet Explorer not send HTTP post body on Ajax call after failure? worked.
This can be done in IIS7 by following the instructions in How to configure HTTP KEEP-ALIVE in IIS 7
i have only used Telerik Ajax controls so far, and my observation is if an exception occours in a Ajax enabled control, nothing happens. No exception report, no action. nothing.
Maybe you should test you app without ajax to identify any problem spots
My initial thought would be that something is happening where the javascript is erroring out (un-caught) and aborting the async postback.
If you can get this to happen in a development environment, you might want to try error handling the window.onerror event and throwing some alert boxes up. It might help to see where possible errors occur.
have you tried:
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(yourButton);
It's seem to me, you have issue with Update Panel.
Define the following properties of Update Panel if you are using more than one update panel and updation of one panel change the data of other update panel.
For the UpdatePanel
ChildrenAsTriggers = true
EnableViewState = true (if you are using this feature)
UpdateMode = Always
Use the same properties for other update panel in your same page.
If you find it useful, please mark it as your answer else let me know....
Try commenting out Update panel if any. Then try to click button there must be some error on the page. I've also faced similar issues.
In my case none of the events (either button or check box) were firing. I was able to overcome by this problem using following way.
In my master page I had closed a tag referring to an external .js file with /> notation instead of <script></script>.
for Ex: chanage <script src='../../Scripts/common/menu.Js' type='text/javascript' /> to <script src='../../Scripts/common/menu.Js' type='text/javascript' ></script>
Hope this will help you,
Ramesh