Showing posts with label fairly. Show all posts
Showing posts with label fairly. Show all posts

Monday, March 26, 2012

How do I distinguish between AJAX postback and regular postback?

I just installed Ajax 1.0 with VS2005 SP1 and am trying to add AJAX to an existing site.


However, the site right now has fairly complex code in the master page defined in Page_init, Page_load, and PreRender events. I'd really like to skip those calls if it is an AJAX post back. I looked at the Page class and found IsCallBack and IsPostBack, both of which will not be triggered by an AJAX post back.

I thought of using a hidden variable (something like AJAXCall) and using a Javascript to set a value with every control that can trigger an AJAX postback, but that seems like not the right way to do it.

Does anyone know how to tell the difference between the two, or is it possible to skip Page_init, Page_load, and PreRender events with an AJAX call?

Thanks,

Ming

Yes you can, but you have to use UpdatePanel.

Girijesh:

Yes you can, but you have to use UpdatePanel.

I have tried the following setups with no success. In the master page, I included my script manager. Then I had an update panel with a button which updates a label with the system time. This takes about 10 seconds to update. The debugger tells me it executes Page_Load, Page_Init and PreRender.

Then I tried to include an update panel with a button inside page that inherits the master page, it also goes into all 3 methods. I tried this with my existing website, as well as a brand new AJAX enabled website.

Any ideas?

Thanks,


Ming


Hi Ming,
You can use ScriptManager.IsInAsyncPostBack property to distinguish them.
Hope this helps.

Raymond Wen - MSFT:

Hi Ming,
You can use ScriptManager.IsInAsyncPostBack property to distinguish them.
Hope this helps.

It worked like a charm. Thanks for telling me exactly what I was looking for.

Thanks!

How do I convert a Non-Ajax ASP site to AJAX?

I have a fairly large project that is an standard ASP.NET C# site and I'd like to be able to use soem ajax on the main page, nothing big. I've installed ajax and the sample site runs fine, (of course it's been created as an ASP AJAX site from the beginning though). How do I make my ASP site work with ajax? The web config file?

Checkout these videos:
http://www.asp.net/learn/videos/view.aspx?tabid=63&id=81
http://www.asp.net/learn/videos/view.aspx?tabid=63&id=82


I followed the steps in the first video but when I try to add a ScriptManager to a page on my site I get the following error

Error 29 The type or namespace name 'ScriptManager' does not exist in the namespace 'System.Web.UI' (are you missing an assembly reference?) C:\Path\Default.aspx.designer.cs 74 41

EDIT: I found out how to fix it. The video doesn't say that you had to add a ref to the dll. So after adding a ref toMicrosoft.Web.Extensions.dll, everything seems to work