Showing posts with label callback. Show all posts
Showing posts with label callback. Show all posts

Monday, March 26, 2012

Calling a JavaScript function after return from callback in UpdatePanel

Hi all.

I am trying to solve this focusing problem inherint in Atas, I have a 90% generic solution, but am missing the last piece to the puzzle.

I need a way to invoke a JavaScript function after the UpdatePanel has returned from a server callback.

I know this is pretty simple to do without an UpdatePanel, unfortunately I am kinda tied into the UpdatePanel.

Any help??

Thanks

Hi,

I had the same problem. This is the solution I could found.
See this post for reference:http://forums.asp.net/thread/1290506.aspx

function pageLoad()
{
$object("_PageRequestManager").propertyChanged.add(BindOnLoad);
}


function BindOnLoad(sender, args)
{

if (args.get_propertyName() == "inPostBack"){
if (!$object("_PageRequestManager").get_inPostBack()){
AtlasPostBack();}
}
}

function AtlasPostBack()
{ //Runs at every postback. This allows us to run things that need to be taken care of
//after postbacks

alert("partial postback is done");
}


Thanks,

I also found that from the server side, registering a script as a startup script will make it fire on every callback.

Page.ClientScript.RegisterStartupScript.

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 Scope on the client

I've started to play around w/ some of the basic Atlas features, mainly calling a web service from the client. One thing I noticed is that scope is lost during the asynchronous call to the server. If my javascript caller & callback method are part of an class, I've no way of telling Atlas to invoke the callback method w/ a specific object's scope.

Is this possible to do?

Cheers,
BobbyYou have a userContext parameter which you can pass as part of yourasynchronous call, that is what you can use to get back to the contextof your call, i.e. you can pass the object who's scope you want back aspart of the call...

Hope that helps,
-Hao
As I understood it, the userContext serves as a holder for contextual data that can be used inside the handler as an object - scope is still lost. Consider the following js class example:

TestClass = function(prop1)
{
this.propertyOne = prop1;

this.test = function()
{
MyCallbackServiceClass.Test({onMethodComplete: this.testCallback, userContext: this});
}

this.testCallback = function(result, user)
{
alert(this.propertyOne);
}
};

var t = new TestClass("This should persist before and after callback");
t.test();

When propertyOne is alerted in the testCallback method, it will be undefined because the scope is not preserved. I don't want the object as a parameter - I want to be operating within that object.
Mike Harder from the ASP.NET team, being the top-notch guy he is, answered this question for me. The scope is maintained by using a delegate.

CSharper.Net.CallbackService.Test({ onMethodComplete: Function.createDelegate(this, this.testCallback), userContext: this });

Callback returns wrong SQL results!

I have a page that has buttons to change values in a few tables. When I use Postbacks it works fine, when I AJAXify it it shows the same results as it did before. Here's the strange bit, if I make a second change it shows the expected results from the first change and so on. It seems to always be one change behind.

I'm going to make a very small version of the page and post it here if it still happens.

It is only happening on one table. It is a very large table but I shouldn't think that would matter if the original Postback method works fine.

Does your AJAX.NET enabled page use a full Web Service? If so you install WSE 3.0 and turn on the trace utiliy. This should show what is being sent and recieve.

CallBack on ContentPageHolder

Hi everyone,

I have a Master Page called AppMaster.master And I have two aspx pages: Default.aspx and News.aspx.

On my AppMaster.master i have one Menu (top of the page) and Ads (left and right of the page). I have a ContentPlaceHolder in AppMaster. When i click on Home the page refresh and go to /Default.aspx, the same thing for /News.aspx.

I want to refresh only the content of the masterpage using callback or AJAX. I probed two methods but i can't refresh only the content. When i click news on the menu of the master page refresh only the content showing /News.aspx without postback. I used the updatepanel but it does'n work.

Can you help me please? Thanks...Confused

This is your scenario?

1) You have a master page,

2) You have two content pages that use the master page,

3) You want to refresh the UpdatePanel on the content page when someone clicks a link on the Master Page?

Check this out, and if this does not help you then let me know:http://www.ben-rush.net/blog/PermaLink.aspx?guid=d29bafbb-35f5-425e-9105-c1ddaae3b003&dotnet.

...it's possible I don't understand exactly what you're trying to do.


Option 3. I have a Menu with the MenuItemClick method.

Thank you very much...


Option 3. I have a Menu with the MenuItemClick method. It doesn't work because new MenuEventArgs doesn't work :(

Thank you very much...

CallBack issues with AjaxControlToolKit

Greetings.

We recently encountered a problem while using the AjaxControlToolkit library. We have designed a "one-page" project, whereas none of the controls is present in the markup code at startup. At some point after the page has already been rendered we make a AJAX Call to our WebService which is responsible for programmatically creating controls, put them into a server-side page, renders the content, splits markup, javascript and reference scripts, and finally sends this three split up parts to the client through the callback.

This scenario works fine as long, as we stick to the standard webui controls or even the ComponentArt controls. But when we were trying to implement a AjaxControlToolkit control, the whole thing failed. The procedure was nearly the same when adding a normal webui control, only that we had to programmatically add a ToolkitScriptManager to our server-side created page where we throw in all the controls. We added a ToolKit control, rendered the page, split it up as usual and sent the results to the client.

The rendered markup still looked good, and the referenced scriptfiles which the client had to reinclude seemed ok, too. But the javascript rendered throws an error, which we can't tail. On one machine it throws an "AjaxControlToolkit is undefined"- javascript error, on another it throws a syntax error which is very vague.

So has anyone tried to programmatically implement the AjaxControlToolkit recently and any clues to what we seem to have missed? Help is really appreciated since we have some kind of deadline, and really wish to implement the cool features of the toolkit :)

Best regards and thanks in advance.

Hi,

Based on your description, I have a general idea of what are you trying to implement. Though, in my opinion, it's cool but may be not that efficient.

Can you create a small sample to illustrate the issue more intuitively, so that I can use it directly and try to find out the cause.

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

Callback for dynamic populate control

When I call the populate method of dynamicpopulator control it calls the method as set in the ServiceMethod property.

How do i know when this method has completed execution so that I could perform some other task.

Is there a callback that I can access that tells me that the populate method has completed?

Please advise.

There might be a way to access the callback handler of the webservice proxy that gets invoked, but I'd say that an easier way would be to use the CustomScript property to call a function of your own design which returns to a handler you set up to do what you're looking for.

CallBack Fails

In my website I had a callback function that works perfectly fine, but sometimes it fails and doesn't work.

I am not getting the point of failure. Is there any reason for callback failing.

Please post the code, callbacks can fail when you register the same call back function somewhere else, also remember that every control in that page will received the callback.

Callback after UpdatePanel

Is there a way to use a callback function in JavaScript after UpdatePanel complete

just like you can do when using a web service or PageMethods?

As so far, you?can?not?use?a?callback?after?asp:Update?is?updated?completely.Maybe?this?could?be?implemented?in?the?near?future.But?
you?can?define?a?LoadCompleted?event?in?a?custom?UpdatePanel?and?then?call?a?callback?after?it?updated?completely.?
If you would like to use callback,web service or PageMethods is better selection.
Wish this could give you some ideas.
yes but the only problem is that in web service or PageMethods (static) you don't have access to the controls on the page.

I found a solution to my problem.

and it is very simple also:

<script type="text/javascript" language="javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(PageLoadedEventHandler);
function PageLoadedEventHandler() {
// custom script
}
</script>

Callback (ICallbackEventHandler) and Atlas. Can they work together ?

I am new in Atlas. It seems very simple to use (Update Panel). However, I have several composite controls that use theICallbackEventHandler. When I mix them with Atlas UpdatePanel they do not work.

Any suggestions.

Thanks

We are currently investigating such issues. Thanks for the report.


Are there any news conerning this issue?

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

Now when I place this control on an UpdatePanel, the javascript:form.submit() raises a postback, but not a partial postback... Do I have to register the javascript somewhere else (expect RegisterClientScript or so)? Or is there a way to make a postback in order that the server updates the UpdatePanel with a new image? I tried the Callback (standard provided by ASP.NET 2.0), but this seems only to be for delivering a string value from server to client (at least I couldnt kick off any partial update of the page..)

Regards,

Ray

Hi,

Can you say if controls using IcallbackEventHandler will be supported when used in Atlas UpdatePanels?

thx


As far as I can see, I don't think this is possible at all, since the two postbacks are happening in two different contexts. It would probably require a change to the whole javascript callback library included in ASP.NET 2.0. What we need here is the ability to send two events back to the client, and returning them all in one context.

Having said that, I really really wish this was possible. Although the ASP.NET AJAX library has some really cool controls, there will always be cases where you would need to supplement with your own AJAX-style controls, and the events on these controls should trigger fx. the UpdatePanel.

Callback

Hi ,

any body can explain about CALLBack

Here is a simple code that shows how callbacks can be implemented in Ajax in .NET 2.0

http://www.codeproject.com/Ajax/ContextSensitiveHelp.asp

HTH

VJ


did u have any idea about the aborting a web request ?


Hi

Is this a related question? I am unable to relate callbacks to aborting a web request. Could you explain that further.


ok , in my web application we are having two buttons (titled as 'Generate Reports' ,'Cancel') whenever the user click 'Generate Report' button my application fetch the data from database and display it in a webpage , meanwhile if the user clicks 'cancel' button the webrequest have to be canceled and the old state of the web page to be maintian as it is .


Hi

I figured that it was a different question and trying to answer that with others on your other post. Meanwhile let me know if the callback part (which this query) answered your query or do you need any more input ?


Hi all,

Here is a quite good article forCallBack.

Best regards,

Jonathan

call web service using ASP.NET AJAX with javascript without callback function

Hello,

I'm trying to create a custom validator with a ValidatorCalloutExtender all in an Update Panel. As everyone knows the callouts do not currently display automatically after a server post-back and will only work for custom validators which utilize client-side validation.

When i call the javascript function from validator callout extender i must return the args.IsValid method before the function ends. If i use a callback function and try to return the args.IsValid from there the validator can't react because the IsValid method is set to late.

In conclusion, with AjaxPro framework this example works

 function descriptionRequiredValidate(source, args){
var ajaxResult = FileAdmin.AjaxMethods.IsDescriptionRequired(...);
var descriptionText = document.getElementById("tbFileDescription");
var descriptionRequired = ajaxResult.value;
if(descriptionText.value =="" && descriptionRequired){
args.IsValid =false;
}
else{
args.IsValid =true;
}
}
As you can see no callback function is required but when i try to use the ASP.NET AJAX with a web service i can't read ajaxResult. Do i make a mystake somewhere or this tipe of response(without callback) only works with ajaxpro 

Your simplest path is to move your final declaration of validity to the OnSuccess handler of the service call.

Call the method bound to an linkbutton after ajax callback

Hi everybody

I just have the following problem:

I created a ASP-LinkButton and added a method in the code-behind file for its onclick event. Then I added a break point at the beginning of the method to check if it's called.

Now I added a JS which calls the __doPostback("xxx", ""); exactly like the LinkButton does and everything works fine.

Now I add a Webservice, which validates my input and if everything works fine, its callback should call the click method of the asp-button. Guess what happens: the postback is called, but not the event of the button. If I do this before outside the callback - everything works fine, so I know the code is correct.

I even tried to add a "window.setInterval" timer which always checks a bool and calls the postback as soon as the bool is turned to true ... Then I set the bool after the callback and guess again: The postback is called but not the method ...

I don't have any further ideas for workarounds - anyone got a hint for me?

THANKS!

Hi,

Now I get a general idea of your situation. But your description doesn't give me sufficient information to find the cause.

Accordingly, I made a sample, please try it.

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> <Services><asp:ServiceReference Path="WebService.asmx" InlineScript="true" /> </Services> </asp:ScriptManager> <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton></div> </form> <script type="text/javascript"> var count = 0; function callBack(result) { if(result) __doPostBack('LinkButton1',''); } function callWS() { count++; WebService.ShouldCallBack(count, callBack); } window.setInterval(callWS, 2000); </script></body></html>
using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partialclass Default3 : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e) { }protected void LinkButton1_Click(object sender, EventArgs e) { Response.Write("Linkbutton is clicked on " + DateTime.Now.ToString()); }}

<%@. WebService Language="C#" Class="WebService" %>using System;using System.Web;using System.Web.Services;using System.Web.Services.Protocols;[WebService(Namespace = "http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.Web.Script.Services.ScriptService]public class WebService : System.Web.Services.WebService { [WebMethod] public bool ShouldCallBack(int count) { return count == 5; } }
Hope this helps.

Saturday, March 24, 2012

Call a client JavaScript function after each and every AJAX callback

Hi,

I have a DropDownList, which is enabled or disabled depending on the state of a CheckBox. I am doing this in JavaScript. I have a function which checks the state of the CheckBox, and sets the DropDownList as either enabled or disabled accordingly. I have attached a call to this function to the 'OnClick' attribute of the CheckBox so it gets called each time the CheckBox is used.

All of this is in an UpdatePanel, along with some other functionality which is not directly related. The problem I am having is that each time there is a Postback to the server (or rather I should say a Callback, as we are in an UpdatePanel), the DropDownList is changed to enabled, even if it was disabled before the Callback.

I thought an easy way to solve this would be to call my 'Disable the DropDownList according to the state of the CheckBox' function after each Callback.

So... how can I set my page to call a JavaScript function after each Callback?

Thanks...

Hi,

I'm using this for that task:

function pageLoad( )
{
Sys.WebForms.PageRequestManager.getInstance( ).add_pageLoaded( PageLoadedHandler );
}

function PageLoadedHandler( sender, args )
{
// your code
}

Check ASP.NET AJAX Client Life-Cycle Events for what is pageLoad, also seepageLoaded Event from the same page.



Thanks very much - that is exactly what I needed. I think I need to get down to it and start exploring the whole Sys.WebForms namespace properly.

Thanks again for your help - I'm very grateful.