Showing posts with label regular. Show all posts
Showing posts with label regular. 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 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.

Design Time Support

Hey gang.

I am new to ASP.NET and as well ASP.NET AJAX. I am loving how this framework can turn a regular form into an AJAX form with very little work.

One thing I am struggling to understand though is why AJAX controls are much much difficult to develop/handle. One example is it seems working with ASP.NET AJAX you have a ton of those gray boxes all over your designer window because none of the AJAX controls have any designer support. Is there any way to make this possible? Once the design surface begins not having any comparison to the live look the designer becomes irrelevant in my opinion.

Thanks and take care.

Anyone? One of the greatest strengths thus far building custom controls etc is the ability to see your page in the designer etc. When using TabContainer for example from the AJAX toolkit, all the controls you put inside of the TabPanel you cannot see in the designer, so my large form I cannot see what it looks like without running. This kind of goes backwards as far as Visual Studio experience is concerned in my opinion. No purpose for smart tags etc if all my contents are not visible etc.

Am I missing something here?

Thanks and take care.


When you create a Toolkit component, a designer class is created, so all the plumbing for creating a great design time experience is there. We've chosen not to focus on this for a few reasons:

1) Many of the components in the Toolkit are Extenders. For the PopupControl extender for example, what UI do you show at runtime

2) Most of the work in AJAX components is done via JavaScript by manipulating the DOM. The designtime isn't really running in the same context so you can't easily share any of the code.

3) There is a basic property-setting experience that the Toolkit does provide you. The Extender itself has a "TargetControlID" property which tells which component it's associcated with. Then if you click on the extendee, you'll see an "Extenders" category show up in the property browser that allows you to modify and set up properties via that experience.

4) The next version of the Web Designer will have a better design experience for extenders (we're currently working with them on what that should look like) but it's still not very UI focused.

So that's kind of where our thinking is at.

Hope that helps!

Shawn


Thanks so much for the reply!

I am glad design time in the future is being considered. I just find it dissapointing that some very basic design time is missing such as again TabContainer. I throw a big form into a TabContainer it should atleast render on the designer so I can see my form. This is just my opinion though. Also I think (possibly new version of VS?) extenders shouldn't be cluttered all over the designer. Perhaps if an extender is linked to a control, if I right click on that control a list of extenders is visible, or some sort of ExtenderDesigner interface.

I understand what your saying but, going from what I am learning in ASP.NET and how rich the framework is and how great the development process is, it seems if I move to heavy AJAX pages, I lose all of that and my designer surface will be all blank because my controls are contained in TabContainer's etc.

I also understand that its hard to represent everything since a lot occurs via Javascript but I think there may be a happy medium somewhere here. I am finding my WebForm just is a bunch of extenders in the designer and I cannot see anything but extenders.

Thanks again and take care.


We hear you. You're right - things like TabContainer are a different type of control and should have better design time support. It's easier for the controls than for the extenders.

On the topic of the extenders, yes, we'll be making these a little less obtrusive on the design surface - you're absolutely right.


Wow cool. Thanks :) I am really liking the new attitude on a lot of the new projects/CTP's.

Thank you so much for listening to the community. I just want to make sure these new technologies continue to be at the level all of MS's developer tools are at. The best available in my opinion.

I am actually working on a Form Generator control. The idea is you set a bunch of inputs, and set their parameters (required, validation type, invalid/missing messages) and the generator just creates all the objects required to get the job done. I am myself having a tough time with getting full designer support.

Is there anyone I can speak to about this? I was using the Dojo framework to do all the JS but now with alot of the ASP.NET AJAX controls I think similiar could be done with some of these. In addition to this functionality the next level would be to simply pass it a DataSource or something similiar and it would auto-detect the fields, data types and auto-gen a form etc.

I would really like a bit of help though since I am struggling with some of the designer based stuff. I have been posting on the newsgroups etc but haven't been getting any helpful insight.

I think if I could get a bit of help I would then release it or contribute it if its usable.

Do you know of someone/somewhere that would be the proper place to speak about design time support?

Thanks and take care.