Showing posts with label postbacks. Show all posts
Showing posts with label postbacks. Show all posts

Wednesday, March 28, 2012

Multiple Postbacks for AJAX

OK...I'm trying to think of the best solution for this situation:

I have an asp.net AJAX enabled website where the user can run complex queries off my SQL Server database. Some of these queries can last quite a few minutes to complete. What I want to happen is when the user clicks a button to run the query, the user can still move around the website while the query is running. And when the query is done, it basically alerts the user it is finished (by updating a label on the site, for example). So, I tried to do this in AJAX, but the problem is (as far as I understand it) is that, by default, the last postback takes precedence, so that if the user clicked another button after he clicked the run query button, the query can not post back to the site saying the query is done.

So I have a couple of questions:

1) Is there anyway for the site to respond asynchronsly to multiple postbacks?

2) If I make multiple postbacks, will all the calls still finish processing? Is it only that it can't post anything back to the server? For example, if the user ran a query that inserted rows into a table, and he clicked somewhere on the page, will the first postback still finish to completion?

3) Would any sort of multi-threading work in my example?

Thanks for any responses!!

-Howie

hello.

well, yes, you can, for instance, make several web service calls. you cannot do the same thing with an UpdatePanel since the last postback will, by default, cancel the previous one. what i think you should do is built some sort of queuing for packaging the client queries and sending them to the server. and i also think that you should use web services instead of updatepanels :)


Hi, thanks for the response. When you say that the last postback will cancel the previous ones, do you mean that it will cancel the query midway through? (excuse me if I'm being naive). Or do you mean that my code will still execute OK (that if the user wanted to insert rows into the table, that it will still do so without interruption), but I just can't post back a result to the site? Also, what do you mean I can make several web service calls? Would you be able to point me to a site I can read up more about it? (I know what web services are...I just don't know exaxtly what you'te referring to).

I really appreciate your help.

Saturday, March 24, 2012

Namespace for client side Postbacks

Does anybody know what the Ajax namespace for implementing a clientside (javascript) postback is? Ideally I would like to fire a partial postback event to an update panel, pass in some arguements and then capture the event in the codebehind.Did you ever find an answer to your question? I've been looking for the same thing without any success. Every example I find is all about doing things on the client side nothing about the server side using .Net AJAX.

nope. It seems that there is no direct method to call a postback from JS. I find people asking for it all over the place though, so I would hope that MS includes it in the next version.

The work around is pretty good though. You basically have two options, I use option #1.

1) Set a hidden field as a trigger. Through JavaScript, update the value of the hidden field. This causes the Ajax postback as desired.

2) I have read about people placing a "submit" button in a hidden DIV and setting that as the trigger. Again, you submit the button via JS.

Let me know if you get stuck and I can send you code.


Thanks for your reply, actually I'm trying to write a control that uses the UpdatePanel. I wrap my control in it and I've tried adding some buttons to the triggers collection, but when I click the button it performs a normal postback. Is there anything special you've found that needs to be done for something like this to cause an ajax postback? What I'm doing here sounds kind of like your second suggestion, but it doesn't seem to work.

Anything INSIDE an Update panel should cause only an "Ajax" postback, and that includes other controls. Make sure you have the attribute Updatemode set to conditional. Like so:

<

asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="conditional">