Monday, March 26, 2012

With AJAX, Using method="GET" instead of the default "POST" - possible?

Guys,

We are trying to use GET instead of POST to reduce the size of the packets sent to the server with each partial postback.

1) How do I do this? I tried specifying method="get" inside the form declaration, didn't work.

2) is this a stupid idea? Our viewstate can go to 8 kb or so. Does GET always tack on the view state to the

URL string?

Thanks !

http://kochukeralam.com

hello.

well, if i recall correctly, the only way you have to do that is to handle the client initializeRequest or beginrequest client event. for instance, if you choose to handle the beginrequest event, the method will receive a referece to the current webrequest object that is being used to make the call (again, we're talking about client objects, which means writing js). that object has a property called httpVerb which you can set to specify the type of call you're making

and yes, i'd probably stick with the post method...


The way a partial postback works, you NEED the ViewState in order to create an instance of the Page, run through its life cycle, and generate the HTML that needs to be returned to the PageRequestManager. So, even if you retooled it to use GET, you'd need to send the ViewState on the QueryString anyway (which would be difficult in the ~2k max you have to work with there).

You're right to be conscious of the ViewState size though. A better solution would be to look into changing where the ViewState is persisted at. Check this out: http://weblogs.asp.net/scottgu/archive/2006/06/18/PageStatePersister-Extensibility-with-ASP.NET-2.0.aspx


hello. hum, i'm not sure if i'm following. if I'm not mistaken, you can disable viewstate and the page should keep working without any problems...

Sure, if the page is designed to not rely on the ViewState (which is always a good option), then it's not needed for any type of request.

However, I believe the original poster was thinking if he could simply switch to a GET, then he could avoid sending the ViewState back to the server for partial postbacks. That wouldn't work, unless ViewState was persisted on the server side somehow (which would make GET and POST equally performant anyway).


hello again.

oh,. i see...then you're absolutely right.

No comments:

Post a Comment