PLEASE HELP! HttpHandlers crash on me when using ajax!!!!

Feb 14, 2009 at 4:49 PM
Hi guys.  I've been desperately trying to figure out why this error occurs in my app but have NO CLUE why this is occurring.  I'm running out of ideas (and time).
See my issue(and a link to my sample blog) here:

It's something odd on virtual httphandler pages where everything works fine normally but when I have images & links within an ajax updatepanel and try to do an ajax postback, the handler loses the real root directory.

Any ideas, tips, starting points, advice...anything...on how I can go about fixing this (or even creating a work around)?


Feb 14, 2009 at 5:18 PM
I took a quick look at your website.  One question I have is if you took the button out of the UpdatePanel and made it just a normal button, does this problem still happen?  Not sure if it's easy to test that ... but this could help understand if this is an UpdatePanel problem or just a different problem with ASP.NET not resolving the image url correctly.

I also noticed when I first get to your blog (before clicking on any links) that most of your images are coming up as 404s.  There's close.png, default_m.jpg, body.jpg, banner_top_left.gif, login_bg_01.jpg, header.jpg, etc. etc.  I wasn't sure if you were aware of this or maybe it's related to the same problem as your ad image not showing up when viewing category posts.

Also, not sure, but what if you try changing the ImageUrl to "/Images/TemplateImages/ad.jpg" without the tilde ... does it make any difference?
Feb 14, 2009 at 7:27 PM
Hi Ben.  Thanks for your reply.

In response to your questions, yeah if I take the button out of the updatepanel and just do it as a normal button click, it works fine.  Unfortunately, this button click needs to done with ajax though, so that's not an option.  But yes, it looks to be an issue with the httphandler and an updatepanel.

With the missing images, I actually didn't include most in my upload.  I just wanted to quickly upload the site to show the error I was having.  So that part's ok.  They're not related to the error.

Also tried removing the tilde but had no luck.

Feb 14, 2009 at 8:15 PM
I was able to reproduce the problem you're having on my local machine.

The problem is that when you're on the category page, the first time you do an UpdatePanel button click, the async postback is correctly being done to "category/BlogEngineNET.aspx", but the response coming back to the page includes a new 'formAction' with a value like '../default.aspx?id=19770e74-9ec9-4cde-b2ab-e5051aaaf348'.  Then the next time you do an UpdatePanel button click, the async postback is being incorrectly done to ../default.aspx?id=19770e74-9ec9-4cde-b2ab-e5051aaaf348.

I did this Google search and found one solution that solved the problem (there may be other solutions too -- didn't search for very long).  The solution I found was here.  If you add JeffreyZhao's code somewhere in your page, it fixes it so the async postbacks are done to the correct url.  I added his code right before the closing <body> tag.

<script type="text/javascript">
        var form = Sys.WebForms.PageRequestManager.getInstance()._form;
        form._initialAction = form.action = window.location.href;
Feb 14, 2009 at 9:59 PM
Thanks a million Ben!  That worked!!!!  I can't even tell you how long I had spent trying to figure that problem out.

Just out of curiosity though, while your were debugging, how were you able to see the response coming back was something like '../default.aspx?id=19770e74-9ec9-4cde-b2ab-e5051aaaf348'?  I'd be interested to know, since it may save me some time spent working on problems with future ajax errors.

Again, a tremendous thanks for sacrificing your time to help me with this!

Feb 14, 2009 at 10:16 PM
Glad that worked.

I was using Firebug to see the response that came back (Firebug is an extension for Firefox).  Fiddler is another tool I use sometimes to see the request/response traffic with a web server.  Both these tools are free and indispensable ... especially firebug, I've solved so many issues with Firebug I can't even remember how many :)

In this case, before even looking at the actual response, I could see in Firebug's 'Net' tab that the 2nd time I clicked the UpdatePanel button, the request was going to ../default.aspx?id=...  I knew this was wrong because the first time it was going to category/BlogEngineNET.aspx.  And it was on the 2nd button click where the 404 for the image happened.  And actually, the formAction returned in the Ajax request on the second click was 'default.aspx?id=...' without the leading '../' before default.aspx.  So then the 3rd time I clicked the UpdatePanel button, there was a 404 for the actual ajax page request since it was trying to access "category/default.aspx?id=..." which doesn't exist.  So basically, one problem on top of another!