Showing posts with label request. Show all posts
Showing posts with label request. Show all posts

Monday, March 26, 2012

Detecting UpdatePanel postback Vs regular postback

Probably a stupid question...

Is it possible to detect on the server-side whether or not the request is a full post back or an updatepanel postback?

Reason is I have a couple of controls on the page that are rather database-intensive and if since an UpdatePanel postback causes a full page cycle, if I could detect it I could avoid having those problem doing the db-intensive rendering task.

Thanks!

Ben

Hi Ben,

You can ask the scriptmanager if it's in a partial page postback, see my example in VB

If ScriptManager.GetCurrent(Me).IsInAsyncPostBack()Then'is in partial postbackEnd If


EACH CONTROL has its own events. if you bind the other controls in the page load event, enclose them with:

if not page.ispostback then

end if

the UpdatePanel has its own events where you can work on.


hi,

i don't think there is any method to identify which postback is done. According to my observation both postbacks are same


First to Check if it is AsyncPostback you can use the YourScriptManager.IsAsyncPostBack and to detect which control casued the postback use the YourScriptManager.AsyncPostBackSourceElementID.


Thanks Richard, that worked just fine (I knew that had to be simple!), marked your reply as answer.

Thanks all for your replies too.

Cheers,

Ben

Detect if a request is a partial postbak?

Hello,

is it possible to check if the current request is a partial postback or not?


I am getting PageRequestManagerParserErrorExceptions when i use a response filter that does a gzip compression in global.asax and my idea was to detect if the current request is a partial one. I that case i would not apply the filter.


The only question is if it is possible to detect the difference between normal and partial postbacks.

Any hints?

Ciao,

Ralf

ScriptManager.IsInAsyncPostBack.

Thanks!

My only problem is now that the process of applying the filter happens in global.asax and i have to find out how to access my scriptmanager instance (scriptmanager is contained in the masterpage) from within global.asax.


OK, i have added the scriptmanager to the application now so i cann access it from within global.asax but: When performing pagings in a gridview that is contained in an updatepanel the ScriptManager.IsAsyncPostback shows "false" (i have defined the paging events of the gridview as triggers so i expected to see IsAsyncPostback=true)

Is the IsAsyncPostBack property only valid at page level (i mean not useable in global.asax)?


I'm not sure, I'll defer to your experiences as an indicator that it's a page / instance level variable.

The request itself gets modified by the runtime, though, so that if you have an http reuqest fired by your updatepanel, it should have the additional http header of:

x-microsoftajax: Delta=true.

If you check the Request.Headers collection, that should be a way for your module to do the detection you're lookign for.

Hope that helps.

Paul


Hi Paul,

Yes, that helps! Now i can apply gzip/deflate filtersand use updatepanels without getting PageRequestManagerParserErrorExceptions by simply not using the filter on partial postbacks.

Thanks for the hint,

Ralf


Detect AJAX postback in Application.EndRequest

Anyone know if there's a way to detect whether the current request is an AJAX postback or a regular postback from inside the Application.EndRequest event of an HttpModule? I have a module that writes out information to the end of a normal request (using response.write). However, this causes an AJAX postback request to fail. Or maybe there's a better way to append some text to the end of a request than response.write?

Ideas?

Test for (Request["X-MicrosoftAjax"] == "Delta=true"). That request header is present in partial postbacks.


Most excellent. Thanks!

HOWEVER, I'm a bit PEEVED at Microsoft for making the client-side AJAX javascript so sensitive to the data that comes back. If any part of my code does a response.write anywhere, the stupid AJAX Javascript on the client goes wobble-kneed and dies. Sheesh! I'd really like to be able to write out some text (using response.write) in both the master-page AND the httpModule's end_request event, but the AJAX Javascript on the client won't allow it! What a pain.

I've seen some c# code on the internet that shows how to modify the response that AJAX returns, but it's confusing as it's doing text translation (i.e., the function of the code is getting in the way of me understanding what it's doing to the response string).

Thanks for the answer to the original question.


Use some sort of HTTP viewer to inspect a partial postback response, and you'll probably see a way to do what you want to. Once you see it, hands-on, it's not too difficult to figure out how to alter (or see why Response.Write kills it).

I use FireBug for that, myself. I think Fiddler is a comparable IE addon.

Saturday, March 24, 2012

Deployment Question- iframe executor failed ?

Just moved to a new server and Debug output is giving me.. "A web request made using the iframe executor failed. Make sure that the app's web.config registers iframecall.axd"

Of course this doesn't happen in dev/test. The server file from the root up are exactly the same (after I switched it to debug).. Is there something else to configure?

It appears that all atlas/ajax calls back to the server are failing in the new environment. There are basic service calls registered in the script manager and some toolkit controls as well.

Where to start?

Other important things I neglected to mention.. I have already added the iframecall in the http handler & theWebOperationAttribute(true,ResponseFormatMode.Json,true) setting to each of the web methods declorations.


Other important things I neglected to mention.. I have already added the iframecall in the http handler & theWebOperationAttribute(true,ResponseFormatMode.Json,true) setting to each of the web methods declorations.


I use fiddler to make sure the script manager was registering the services and everything looks good. If I point the services back at the dev server they work great?

Fiddler namespace registrations.

HTTP/1.1 200 OK
Date: Mon, 21 Aug 2006 12:32:33 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 582

Type.registerNamespace('NU.Web.ECatalog.Services');
NU.Web.ECatalog.Services.PassortUsers=new function() {
this.appPath = "http://nunettst3:8040/apps/ecatalog/";
var cm=Sys.Net.ServiceMethod.createProxyMethod;
cm(this,"SearchInvoiceApproversByName","prefixText","returnCount");
cm(this,"SearchMaterialRequestApproversByName","prefixText","returnCount");
cm(this,"SearchByName","prefixText","returnCount");
cm(this,"SearchByNameNoLimit","prefixText");
cm(this,"GetInvoiceApproverId","name");
cm(this,"GetMaterialRequestApproverId","name");
cm(this,"GetUserId","name");
}