How to call server side function by javascript using Ajax.Net


I want to call the server side function by javascript function. Is it possible using Ajax.Net (System.Web.Extensions.dll or AjaxControlToolkit.dll)?

If yes then please give me the code or URL.

I found some article using Ajax.dll but I want to use System.Web.Extensions.dll or AjaxControlToolkit.dll.

Please help me.

Thanks in advance





5/1/2007 9:17:12 AM 2181 articles. 0 followers. Follow

9 Replies

Similar Articles

[PageSpeed] 31


Ajax.NET and ASP.NET AJAX, what you want, are completely different implementations so please be sure to use the correct terminology in the future as there are already 100+ AJAX frameworks around.

Here's a tutorial on how to communicate with webservices from ASP.NET AJAX:

Grz, Kris.

Read my blog. Handy Firefox plugins for web developers.

Workaround for non working Mark as answer buttons.
5/1/2007 11:05:08 AM


Thank you for suggestion.

Actualy I do not want to use webservice. I just want to call server side function by using javascript and using ASP.Net Ajax tech. In my web project I am not using any webservice.  To use ASP.Net Ajax tech, is it necessary to use?

Like I have one function at server side in class Management

public string Display(string str)


    return str.ToUpper();


Then how can I call this function by javascript and with ASP.Net Ajax tech to avoid postback. Not with other framework.

Please help me. I am very confused with webservice.

Thanks in advance


5/1/2007 3:59:48 PM


in the ScriptManager on your page you must set the EnablePageMethods property ( After that you should be able to use your codefile methods.

Grz, Kris.

Read my blog. Handy Firefox plugins for web developers.

Workaround for non working Mark as answer buttons.
5/1/2007 4:44:32 PM


 EnablePageMethods is for the static methods of the page, what if my method isn't static and I don't wish it to be so?

Take care,


7/4/2007 8:20:16 AM


 Anybody knoww hot to call non-static method using EnablePageMethods?




8/23/2007 10:50:38 AM


 Anybody knows how to call non-static method using EnablePageMethods?




8/23/2007 10:50:55 AM

EnablePageMethods will only enable you to call static page methods. Also, you need to use mark the method with [WebMethod] attribute before you can call the static method from javascript. Following are two good articles which will throw more light on the subject



4/17/2008 4:18:09 AM
1    // JScript File
3    function CallMe(src,dest) 
4    { 
5    var ctrl = document.getElementById(src);
6    // call server side method
7    PageMethods.GetDate(ctrl.value, CallSuccess, CallFailed, dest);
8    }
9    // set the destination textbox value with the ContactName
10   function CallSuccess(res, destCtrl)
11   { 
12   var dest = document.getElementById(destCtrl);
13   dest.value = res;
14   }
15   // alert message on some failure
16   function CallFailed(res, destCtrl)
17   {
18   alert(res.get_message());
19   }
1    using System;
2    using System.Data;
3    using System.Configuration;
4    using System.Web;
5    using System.Web.Security;
6    using System.Web.UI;
7    using System.Web.UI.WebControls;
8    using System.Web.UI.WebControls.WebParts;
9    using System.Web.UI.HtmlControls;
11   public partial class _Default : System.Web.UI.Page 
12   {
13       protected void Page_Load(object sender, EventArgs e)
14       {
15           TextBox1.Attributes.Add("onblur", "javascript:CallMe('"+ TextBox1.ClientID +"', '"+ TextBox2.ClientID +"')");
16       }
18       [System.Web.Services.WebMethod]
19       public static string GetDate(string when)
20       {
22           return DateTime.Now.ToString();
23       }
25   }
 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>

<script type="text/javascript" language="javascript" src="script.js"> </script>

    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"/>
        <br />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
            <asp:Label ID="Label1" runat="server"></asp:Label> </div>
Mohamed ELMesseiry
Business Solution Developer
6/22/2008 2:00:53 PM
7/12/2008 9:29:28 AM

Similar Artilces:

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: Hope it helps Thanks for the video.  It worked with ajax.dll. I had missed the Script service namespace in web service....

Calling a javascript function from server side, using AJAX timer
 Hello,I am developing a ASP.NET ajax application.I am using a timer:<asp:Timer ID="Timer1" runat="server" OnTick="Timer_Tick" Interval="5000" />      The only thing I want to do is to call a javascript function on every tick of the timer: protected void Timer_Tick(object sender, EventArgs e)        {            ClientScript.RegisterClientScriptBlock(this.GetType(), "blink", "<script>blinkit('2');</script>");      &nbs...

Calling Server Side VB.NET code with Javascript just to call a sub method
Hi, Can anyone please give me a clue on how to call my Server side  CalculateResult() method from Javascript code when onchange event is fired??  thanks in Advance Dollarjunkie.Net Web/Software Engineer You will have to use AJAX.  Is there any reason why the CalculateResult logic cannot be handled by Javascript? Best regards...Josh Stodola ← Come check out my blog! The reason is this... I need to have the code go get information based on what is retrieved and then do some calculations based on that and then display the information in one of my controls. I am n...

How do I call a .NET function using javascript?
Hey all, I would like to develop a firefox extension. I know I need to write in JavaScript - how do I call a function/dll that I wrote under c# and use it through my JavaScript code? Is there any module I can use? Thanks in advanced, YoS. ...

How can I use JavaScript to call .NET function?
Hi,   I want to use javascript to call .net function like this  protected void somefunction(object sender, EventArgs e) {         MultiView1.ActiveViewIndex = 3; }  I've used this method but it doesn't work like I want In aspx page <script language="javascript" type="text/javascript">function receivceCallFromFlash() { var location= "uk";CallServer(Location, ""); } </script>   <script language="javascript" type="text/javascript">functi...

call webservice using javascript without using AJAX and
HI,how can i call a webservice without using AJAX and, using any protocols?Thanks.X you could skip using an AJAX framework and issue an xmlHttpRequest directly Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: Hi, thanks mbanavige.well, is there any disadvantage of using xmlhttprequest?and one more question can AJAX also work on other web servers than IIS like Apache? and is AJAX compatible with all browsers other than IE?how can i call a web servi...

How to call server side(C#) function from Client side(Javascript) function?
Hi i have used below functions,  function HandleOnClose() {// this function will be called after clicking browsers close button in Internet explorer if (event.clientY < 0) { event.returnValue = 'Are you sure you want to leave the page?'; } // if he clicks ok then i need to call one server side function in this instance.. else not. } <body onbeforeunload="HandleOnClose()" leftmargin="0" rightmargin="0">other controls in page..</div>  How to achieve this? Thanks MS AJAX Extensions would be the option of choice here. Combined with webservices you can...

how to call server side function using ajax pagemethods
hi Iam using  accordion control in which on contet click , i will have to fill the images,textbox as per the value of the content field herer i have added the code in which iam passing the value ie "dSET1.Tables[0].Rows[j][0].ToString() " which will deceide what to fill in the textbox ,image..."for (int j = 0; j < dSET1.Tables[0].Rows.Count; j++) { lblContent.Text = "<b><a href='#' onclick='Confirmcheck(\"" + dSET1.Tables[0].Rows[j][0].ToString() + "\");' Class='AccordionLink'>" + dSET1.Tables[0]....

Call Server-Side function using Javascript OnClick?
Hi, I have a .ASPX page that features linked images (ie.. <div id='nav1' class='button'><a href=#></a></div> instead of buttons, so I can control the image/position/rollover using CSS. I have some server-side calculations I want to run, is there any way to trigger those calculations using the OnClick action? I've tried setting the form method to POST, and one of my links to 'submit,' but I may not be doing that right. If nothing else, can I use JS to trigger a PostBack? Thanks, Jesse You can o in the following way  1. Ad...

Call VB.NET existing function or using Javascript ..or....
 Hello All, I'm new to programming and would appreciate some much needed help. I have hit a wall with one of the issues. Basically first the overview and then the nitty gritty details. I am working on .NET Framework 1.1 and using VB.NET. I had an existing ASP.NET grid in a user control which I have replaced using a third party AJAX Grid (Component Art) instead. Implementing the grid was very easy and up until now it has been a pretty smooth ride. However, now I have one column (out of 8 total) which displays a small table when your mouse hovers over it (in the original ASP.NET ...

Sending SMS using or using or
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

How to call a javascript function from a server-side function
Hi. I'd like to know if it's possible to call a javascript function from within a server-side function. I know it's possible to associate a javascript function with a control event but I'd like to call it from within an function.  Thanks, Samir Zattar Hey, There are several ways to do it, all through the Page.ClientScript property.  You can write a script through RegisterClientScriptBlock or RegisterStartupScript, or if you have a script file you can write a reference to that file.Brian"Trust in the Lord and do what is good; dwell in the land and ...

call a server side function from javascript function
hello i have apage that is contained in MasterPage (contents) i have a HyperLink and i want to call a serverside function is it possible? i am writing C# nirnironIf i helped you please mark as answered.. in your page_load event, you can reference controls on the masterpage by MasterPage.FindControl("....")  Peter Kellner and blogging athttp://PeterKellner.netMVP, ASP.NET  Use the "LinkButton" control...  Looks the same as a hyperlink, acts the same, and you can catch events from it. no... ok this is the scenario... i have ...

how to call server side function in javascript function
right now I have a question. I have a javascript function which created a textfield. what I want to do is when the user type in the value into the textfield, it will call the function in the server side and search the data in the database. I wonder is it possible to do that? And how to do it, can anyone some me some example..thx    look into ajax autocomplete Liming XuJumptree ASP.NET 2.0 Project Management - With Source Code, Free to Non Profit Org and Effectively Manage Projects/Tasks/Milestones Superwong-You definitely want to use Ajax (as was suggested). Since you're u...

Web resources about - How to call server side function by javascript using Ajax.Net -

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

Lightbox (JavaScript) - Wikipedia, the free encyclopedia
On a Lightbox-enabled page, a user can click an image to have it magnified in a Lightbox window, which resizes itself according to the size of ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
about dmoz - help Top : Computers : Programming : Languages : JavaScript : Tools : Obfuscators Tools for obfuscation/compression JavaScript code. ...

Facebook File-Transfer App Pipe Relaunches, Now Works Via JavaScript, WebRTC
... allowed Facebook users to send and receive files up to 1 gigabit in size. A new version of Pipe debuted Monday, and the app now works via JavaScript ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

JavaScript SDK - Facebook-Entwickler
Overview The JavaScript SDK provides a rich set of client-side functionality for accessing Facebook...

Senior Front-End Developer (Javascript and AJAX)
Company: Sometrics Category: Software Development Location: Los Angeles, CA How to Apply: Description: We are looking for ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken .… ...

Resources last updated: 12/3/2015 9:54:57 AM