Showing posts with label http. Show all posts
Showing posts with label http. Show all posts

Monday, March 26, 2012

Callback to server (by javascript) which updates an UpdatePanel

I already posted this in http://forums.asp.net/thread/1178950.aspx
but it seems to be a very general questions about callback in ASP.NET 2.0


I have a custom (image map like) control which reacts to clicks bya javascript. the javascript part sets postback values like x, y, andraises a postback by form.submit().

Now when I place thiscontrol on an UpdatePanel, the javascript:form.submit() raises apostback, but not a partial postback...

Do I have to register thejavascript somewhere else (expect RegisterClientScript or so)?

Or isthere a way to make a postback in order that the server updates theUpdatePanel with a new image?
I tried the Callback (implementing ICallBackProvider), but this seems only to be for delivering a stringvalue from server to client (at least I couldnt kick off any partialupdate of the page..)

Regards,

RayHi Ray,

Executing form.submit() will never cause a partial postback. A partial postback occurs within an UpdatePanel if the following is true. The control causing the postback is within the UpdatePanel or the control causing the postback is setup as a trigger of the UpdatePanel. These are the two situations that cause a postback.

In your case, there are a couple of options (or lots of options that I can't think of).

One option is that your custom control's click event could cause a postback. Causing a postback boils down to executing a JavaScript command: "__doPostback(params);". I'm not sure how you're registering the client side JavaScript that sets postback values X and Y, but you can generate the necessary JavaScript to cause a postback by executing "Page.ClientScript.GetPostBackClientHyperlink (params)" in code behind. You then associate this code with the onclick clientside event by executing "this.Attributes.add("onclick",postbackCommand)." It seems that this line of JavaScript would go after whatever other clientside code you needed to execute that set X and Y.

If for some reason doing it this way is not an option, you can always place a hidden button (not .NET hidden but CSS hidden) within the UpdatePanel and programmatically through JavaScript, click it. This presents some problems because you have to have the ClientId to find the exact button you need, which can be difficult as .NET generates this Id for you based upon control hierarchy.

So those are two options for causing a postback in your situation.

Hope this helps.

- Joel

Hi Joel

Thank you, the first option (__doPostback) works great for me.

Regards,

Ray

CAllback Http handler http module

Hi all,

Can anybody tell me how to generate callback.This call back should NOT be in on aspx page .

I this its solution is Http module or Http handler but i dont have idea to implement .Give me some reference and sample code or examples for implementing call back using http handlers or httpmodule

thanks

Could you please describe in more detail what you want? A callback (as in ICallbackEventHandler) that is not on a page does not make sense.


I HAVE A WEB CONTROL CLASS LIBRARY IN WHICH I HAVE A .js FILE ADDED AS RESOURCE FILE . FROM THIS FILE I WANT TO SEND A CALL BACK AS I WANT TO USE "AJAX". BUT AS FAR I KNOW I REQUIRES A .aspx.cs PAGE WHICH I CAN'T ADD IN THE CLASS LIBRARY. HOW WILL I DO THIS TASK.

ANY KIND OF HELP IS APPRECIATED


ICallbackEventtHandler can be implmented in a Controt, it not true that it can be only implmented in a page. For more details of creating controls with ICallbackeventHandler checkout this articlehttp://msdn.microsoft.com/msdnmag/issues/05/01/CuttingEdge/default.aspx