пятница, июля 18, 2008

Перестала работать UpdatePanel :)

Что удивительно, она перестала работать :) то есть все тригерные контролы стали приводить не просто к перегрузке содержимого updatePanel, а к полной перегрузке страницы, т.е. чего хотелось избежать ( именно постбеков) так и не получилось...

причем в процессе отладки было видно, что серверный код обработчика вызывается, но на стороне клиента происходит исключение вида (все таки отладка на стороне клиентского js великая сила :)) -

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

т.е. судя по всему, тот код который отдавался в процессе калбека со стороны сервера клиенту в onSuccessHandler не мог быть распарсен, что приводило к тому, что updatepanel не могла перерисовать свое содержимое, и наверно самое верное решение со стороны ajax client runtime было обновить всю страницу ..


на самом деле, сразу было очевидно то, что дело было в движке проекта или в сайте, в работе самого ajaxToolkit script manager сомневаться не приходилось, так как на отдельном простеньком сайте скрипт менеджер и update panel вели себя так как и положено;

порывшись полчаса в инете, наткнулся на интересное описание того как избежать таких ситуаций:

http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx

а именно:
вырезка

Why do I keeping getting a PageRequestManagerParserErrorException?

Well, chances are you're doing one of the things mentioned in the error message. Here are the most common reasons and why they don't work:

1.
Calls to Response.Write():
By calling Response.Write() directly you are bypassing the normal rendering mechanism of ASP.NET controls. The bits you write are going straight out to the client without further processing (well, mostly...). This means that UpdatePanel can't encode the data in its special format.
2.
Response filters:
Similar to Response.Write(), response filters can change the rendering in such a way that the UpdatePanel won't know.
3.
HttpModules:
Again, the same deal as Response.Write() and response filters.
4.
Server trace is enabled:
If I were going to implement trace again, I'd do it differently. Trace is effectively written out using Response.Write(), and as such messes up the special format that we use for UpdatePanel.
5.
Calls to Server.Transfer():
Unfortunately, there's no way to detect that Server.Transfer() was called. This means that UpdatePanel can't do anything intelligent when someone calls Server.Transfer(). The response sent back to the client is the HTML markup from the page to which you transferred. Since its HTML and not the special format, it can't be parsed, and you get the error.

How do I avoid getting a PageRequestManagerParserErrorException?

To start with, don't do anything from the preceding list! Here's a matching list of how to avoid a given error (when possible):

1.
Calls to Response.Write():
Place an or similar control on your page and set its Text property. The added benefit is that your pages will be valid HTML. When using Response.Write() you typically end up with pages that contain invalid markup.
2.
Response filters:
The fix might just be to not use the filter. They're not used very often anyway. If possible, filter things at the control level and not at the response level.
3.
HttpModules:
Same as response filters.
4.
Server trace is enabled:
Use some other form of tracing, such as writing to a log file, the Windows event log, or a custom mechanism.
5.
Calls to Server.Transfer():
I'm not really sure why people use Server.Transfer() at all. Perhaps it's a legacy thing from Classic ASP. I'd suggest using Response.Redirect() with query string parameters or cross-page posting.



в сущности все сводится к тому, чтобы избежать ручного responce.write(); вспомнив, что в проекте используется дополнительный httpModule, который выводит отладочную информацию и который собственно говоря и осуществляет write(), пришлось его отключить в пользу нормальной работы script manager & update panel, что и позволило избежать вышеописанной ошибки...


1 комментарий:

Konstantin комментирует...

Last year I wrote a fix for AJAX 1.0 on my old blog, looks like many people found it helpful, I wanted to make sure people understood that issue only happened with ASP.NET AJAX 1.0. I cannot reproduce the same problem with AJAX 3.5.

You will encounter this issue when mixing callbacks and postbacks, as callbacks do not use Response.Write and there is not complete Requests to the server.

This is a bug on the MS ASP.NET 2.0 AJAX 1.0, is not that you are doing something wrong, the framework cannot handle the request validation and the exception is thrown. I found that you can catch the exception using the Script manager; information about it here: http://alpascual.com/blog/al/archive/2007/03/26/Code-Snip-_2200_Customizing-ScriptManager_2200_-to-detect-errors.aspx

Or better yet, you can disable the error by disabling the request validation. On top of the webform add: enableEventValidation="false"

UPDATE: setting enableEventValidation does not fix the problem in all the cases. The problem can be cause with a timer in your application as well.

(http://alpascual.com/blog/al/archive/2007/04/26/How-to-fix-Sys.WebForms.PageRequestManagerParserErrorException-in-AJAX.aspx)