Showing posts with label dll. Show all posts
Showing posts with label dll. Show all posts

Wednesday, March 28, 2012

Calling function on Codebehind from client side scripting using ASP.NET AJAX

Hi,

I'm relatively new to the new avtar of AJAX. I've used the Ajax.dll in my previous application to make an AJAX call.

Now my issue is. How do i call a function on my code behind page , from my client side javascript. To elaborate this consider the following.

I'm creating a new ASP.NET AJAX Web Site.

I've Defaul.aspx with following controls.

1. a button.

2.a dropdown.

In my Default.vb page i've a function FillComboValues() that returns a string.

No on clicking Button i wanna run the FillComboValues() function on my code behind.( I DONT WANT TO USE UPDATEPANEL.)

I've read many articles on net to solvemy problem but every example describes how to access a webservice method. none of them have described how to access a pagemethod.

Pls help me out with this ...

Thanks in advance.

----

In previous version of ajax , we needed to register the server side function using <Ajax.AjaxMethod()> _ . isn't there an equivalent way of registering the function.?

Hi,

Same problem for me, plz let me know whether you have found a solution for this or not?

Thanks


Hi, you can only call static functions of codebehind from javascript normally. Create a static function in codebehind and in javascript just call it in the following way:

say your static method is returning some string value, then in javascript you have to write,

var returnedValue = <% ="'" + ReturnHello() + "'" %>


In order to call a function on codebehind you can use either a WebService or an static method. I had the same problem and i used static methods because it′s more like Ajax.AjaxMethod, The first thing to do is to add to the scripmanager the following line EnablePageMethods="true" and then in code behing put [WebMethod] in front of every method you want to use. To call them from your client script, just use PageMethods.[your method name] and you should be good to go....


i am speaking about the code behind file of aspx page (not asmx-webservice). You can not use [WebMethod] in codebehind file.

In previous version of ajax , we needed to register the server side function using[Ajax.AjaxMethod()] {in codebehind} . isn't there an equivalent way of registering the function.?

Pleaes let me know if you have any thing equivalent to this?


SaiTej:

i am speaking about the code behind file of aspx page (not asmx-webservice). You can not use [WebMethod] in codebehind file.

In previous version of ajax , we needed to register the server side function using[Ajax.AjaxMethod()] {in codebehind} . isn't there an equivalent way of registering the function.?

Please let me know if you have any thing equivalent to this?

Alternate method inAjax Extensions is putting the control (for ex:button) in Update panel. All the events that u write for this control are async.

So no need to declare explicitly[Ajax.AjaxMethod()]


asj:

Equivalent way inAjax Extensions is putting the control (for ex:button) in Update panel. All the events that u write for this control are async.

So no need to declare explicitly[Ajax.AjaxMethod()]

Monday, March 26, 2012

Call server side function from javascript using ajax

Hi,

I want to call a server side function from javascript. Using Ajax.dll I am able to call a simple server side function but server side function containing webservice cannot be called. Does anyone have solution for this?

You should start out by watching this video:http://www.asp.net/learn/ajax-videos/video-79.aspx

Hope it helps


Thanks for the video.

It worked with ajax.dll. I had missed the Script service namespace in web service.

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.