Showing posts with label method. Show all posts
Showing posts with label method. Show all posts

Wednesday, March 28, 2012

Update UpdatePanel contents from a web method async call back

Hi,

I have several asp label controls contained in an UpdatePanel.

An asp button control has code behind that calls a web service method using an AsyncCallBack.

When the callback occurs, I need to show the results by setting the text property on the label controls but I cant get the label controls to update.

Does anyone know how to get this working??

Thanks,

Hi, not much use to you I'm afraid but I have a very similar problem. My callback event is from a remoting object rather than a web service and I need to update a gridview rather than text boxes.The callbacks fire at irregular intervals so I can't use a timer to generate a partial postback.

Thanks


Well, you can't really force a client refresh based on a server-side event, unfortunately. The best you can do is use a timer of some sort, despite the fact that the response is irregular. Now, something to realize is that the updatepanel sends all the same form data that you'd normally send for a full postback, so that's a fairly heavy way to do it when you're not sure if you need to or not.

What I'd do instead is have that AsyncCallBack's server-side 'on complete' handler update a variable at the appropriate scope (there's any number of choices to make there as to where to place that variable scope-wise, and what info it should contain; but those decisions are domain specific to your app). Anyway, do that and then set up a simple web service that provides a read-only view of that variable. Personally, I'd use a 'last updated' kind of thing, and have that in the update panel as well, that way you can compare the two times in the next step.

On the client side, create a simple script that fires at a set interval (again, whatever time is appropriate) using setTimeout or the Sys.Preview.Timer object (the latter being a lot easier to use, imo). That javascript function fires off a request to the web service you set up, and in its oncomplete handler, you check the response. If that variable's value indicates that a refresh is needed, then you have the javascript function initiate the updatepanel's asynch postback to refresh all the data.

Now, all that said, I probably would do the whole thing w/ web services myself, but I'm assuming that you need some of the major server-side features that the updatepanel technique allows you to use.

Hope that helps,

Paul

Monday, March 26, 2012

UpdatePanel + Javascript + UserControl

Hi all

I have a Usercontrol which has a scriptblock with a javascript method in it. This is fired by a control within the usercontrol

...

<input type=submit onclick="MyFunction()"/>

...

<script...>

function MyFunction()
{
alert("Hello World");
}
</script>

This works fine on the page until i surround the usercontrol in an UpdatePanel. When i do this i get a js error, cannot find the method MyFunction();

I have tried to use clientscript.Register...Script(); methods, have had the javascript in its own javascript file, have used the defer tag and still it does not work. Currently I have the control in the UpdatePanel and the script tag which points to a js file on the page itself.

I have seen posts like this before, but no-one seems to have solved it. Is this a known issue? Or has someone solved it and I just cant find it on the boards? Or am I simply not doing something?


Thanks in advance

S.

Hi Penny, exact same problem solved here -->http://forums.asp.net/thread/1503014.aspx

:)

Jim


Thanks Jim -

I'll try it over Christmas.


S.