jQuery and ASP.NET first steps

by Arnold Matusz 26 4 2009

This post may be most relevant to those who haven’t had the chance to work with jQuery yet. Lately there is a great hype around jQuery, very many people talk about it, very many write excellent example but most of them target more advanced users.

jQuery is a lightweight (~19KB Minified and Gzipped) JavaScript library which easily enables us to traverse the DOM (Document Object Model), handle events, animate elements, and do asynchronous requests (AJAX – Asynchronous JavaScript and XML). » Continue reading ...

ModalPopupExtender to show a MessageBox

by Arnold Matusz 10 1 2009

Using Ajax in a web application makes a better user experience and if used well, it even improves performance! But it's not all advantages. With the change of a technology, of an approach we need to adjust our way of thinking and the way we apply our solutions for different task.

This might be a bit abstract, so I'll get specific about what I mean. As often met, when you click certain controls on a webpage, you expect to see an outcome, a result or a message as a response to your "request". What Ajax does is ... it replace only certain regions of your webpage. If that region isn't in the visible in the current scroll position of your page in the browser, you won't see the effect. » Continue reading ...

ValidationSummary displayed multiple times in UpdatePanel

by Arnold Matusz 14 10 2008

Restricting the user from leaving certain fields blank is often mandatory, because we don't want to have empty fields in our database, or we may want the user to specify exactly how many products he wishes to order. Asp.net comes in really good here with the Validation Controls. For my example the RequiredFieldValidator is perfectly suited because it displays a little error message for the control it validates.

All is fine until you have 40-50 fields that have to be filled out. In this case it's of good practice to use the ValidatioSummary control which summarises all the error messages from the ValidationGroup and shows them either in text on the page or as a Javascript alert().  » Continue reading ...

Server.Transfer in an UpdatePanel

by Arnold Matusz 6 10 2008

While writing a short piece of code for my global exception handling post I figured out a nice fact. What I wanted to achieve is to have redirection to a custom error page which displays exception details. This can be easily done by using Response.Redirect() (to ex: ~/exception.aspx"), but this will completely lead to another page. This is not usefull if I'm interested in the actual URL where the exception has been thrown. (ex: ~/products.aspx?catid=4&pageid=7 ..."). By using Response.Redirect() you end up with "/exception.aspx" as the URL in the browser.

An obvious solution at first sight is ... we need to use Server.Transfer() which won't create a new Context (i.e.: the url in the browser will stay the same but we show the contents of a completely new page). And of course this is all fine ... until you need to use this functionality in an ASP.NET AJAX enabled website in an UpdatePanel.

By calling Server.Transfer() during an asynchronous postback the following alert will be displayed:

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.
Details: Error parsing near '
<!DOCTYPE html P'.

The reason why you can't use a Server.Transfer() in an UpdatePanel is more and more obvious when you think about what AJAX is. We only request small pieces of markup which replace little portions of a page, the whole point of AJAX is to avoid downloading the whole page again. This means that when triggering an async postback, the PageRequestManager expects to receive some small portion of HTML, but because the Server.Transfer() call was made the actual response is the markup for a completely new/different page (which begins with the DOCTYPE definition, this is what you can see at the end of the exception message).

If you decide to use a Server.Transfer() in an UpdatePanel you can avoid this exception by setting your Trigger to a PostBackTrigger. (i.e. The control which fires the method where Server.Transfer() is called won't cause an async postback!).
» Continue reading ...

About Arnold Matusz

Arnold Matusz

My name is Arnold Matusz. I'm a web developer specialized in .NET technologies with a passion for photography and cars.

View Arnold Matusz's profile on LinkedIn

Who's amung us