Showing posts with label idea. Show all posts
Showing posts with label idea. Show all posts

Monday, March 26, 2012

Call Server Side Function from Javascript

I wan to call Serverside function from Javascript function . We can use it by using AjaxPro.dll Assembly.

Can anybody have an idea how can we do that in new AjaxAsp.net extensions. I dont want to use Webservice . just want to call the web page class fucntion from html page using javascript.

use PageMethods.

there's a tutorial for it under the /docs web services section (all the way at the bottom). Basically, you flag a public static method in your codefile with the WebMethodAttribute and then your javascript can find it by claling PageMethods.myMethodName(params,onsuccess,onfailure) where 'myMethodName' is the name of the method in your page's codefile, params are any parameters it needs, and onsuccess and onfail are js functions to handle those events. You also need to set your scriptmanager's property EnablePathMethods=true.


I have tried this already and its gives me PageMethod undefined Error. ANd i have not found any soln. except of third party
Well, PageMethods do work, so there's probably some small mistake in your code or configuration. Perhaps you could post a sample of one that fails?
My guess is a missing EnablePageMethods="true" on your ScriptManager, though as Paul pointed out, we're just guessing until we can see what you've tried.

Saturday, March 24, 2012

Call function and show results in update panel

Hi,

I've recently dipped into the world of AJAX and want to check if an idea I had is possible with it.

I have a page that takes values passed into from a previous page via a Cross Page PostBack. These values are used in an SQL query on the results page. The problem is that the query is very long, and takes around 5-10 seconds to complete (sometimes longer).

I want to show our users that the page is working in the background, and I believe it can only be done in AJAX. Ideally, I'd like to make a label that says something like "Operation complete" inside an UpdatePanel visible after the SQL query has been completed. I want the rest of the page to complete loading as quickly as possible, and have the update panel display it's message when everything's done.

I can see two ways of doing this:

    Have the SQL query performed on the Page_Load event.Have the SQL query performed directly by the UpdatePanel calling a server side function.

Are either of these methods possible? The first method looks like it should work (maybe with threading), but I'm too much of a novice to know where to start. Can anyone recommend any good tutorials, or show me an example with a simple "Hello World" and Sleep() operation.

By the way, I'm also using master pages.

Thanks for any help you can offer.

Hi,

Please note that on the server side, there is not much difference between handling a normal postback an a partial postback. ASP.NET will create a new instance of the page that being requested to serve the request. And the page will go throught a full lifecycle.
So there won't be much difference between the two ways your posted, but option 2 is a bit better because the operation isn't necessorily to run each time.

I think your problem can be perfectly solved with UpdateProgress Control, please readthis for more information.
Hope this helps.