Click here to Skip to main content
12,830,743 members (42,233 online)
Click here to Skip to main content
Add your own
alternative version


6 bookmarked
Posted 10 Dec 2011

Use AjaxManager to Generate JavaScript that calls the Server-Side Method

, 26 Dec 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Use AjaxManager to Generate JavaScript that calls the Server-Side Method

The original post can be found here.


Due to limited time, synchronization cannot be guaranteed in more than one blog article. At the following address, you can view up-to-date content, hope you understand:

Please download the sample code at the section JQueryElement demo download of Download JQueryElement, the directory is /ajaxmanager/Default.aspx.

This article explains how to use AjaxManager to generate the JavaScript that calls the server-side method, and how to call these methods:


Be sure that you have got the latest version of JQueryElement at the section JQueryElement.dll download of Download JQueryElement.

Use the following statements to reference namespace:

<%@ Register Assembly="zoyobar.shared.panzer.JQueryElement"
 TagPrefix="je" %>
<%@ Register Assembly="zoyobar.shared.panzer.JQueryElement"
 TagPrefix="je" %>  

In addition to the namespace, you need to reference the jQueryUI scripts:

<script type="text/javascript"
 src="[script path]/jquery-<version>.min.js"></script>

Creating JavaScript

In the page, we add a AjaxManager control to create a JavaScript method that calls the server-side method:

<je:AjaxManager ID="manager" runat="server">
   ClientFunction="<javascript method name>"
   ClientParameter="<javascript parameter, ??: name, age>"
   Url="<server-side method url>" MethodName="<server-side method name>"
   Success="<javascript method invoked on success>"
   Error="<javascript method invoked when error>"
   Complete="<javascript method invoked when completed>"

<je:AjaxManager ID="manager" runat="server">
  <je:AjaxSetting ClientFunction="add" Url="handler.ashx" Success="
    <je:Parameter Name="c" Type="Expression" Value="'add'" />
    <je:Parameter Name="num1" Type="Selector"
     Value="'#num1'" DataType="Number" />
    <je:Parameter Name="num2" Type="Selector"
     Value="'#num2'" DataType="Number" />

The above example generates a JavaScript method called add, the generic handler handler.ashx will be called in the method to return JSON data.

Code -:data will be replaced with data or data.d, for more, please refer to Return JSON In different .NET Version.

We can add Ajax request parameter through Parameter, please refer to Through Parameter Object Add Ajax Request Parameter for details.

Set Parameter List of the JavaScript Method

Through the property ClientParameter, you can set the parameter list of a JavaScript method:

<je:AjaxManager ID="manager" runat="server">
  <je:AjaxSetting ClientFunction="add3" ClientParameter="othernum"
  ... >

    <je:Parameter Name="num3" Type="Expression" Value="othernum" />


In the example above, by adding the parameter othernum for the method add3, the value of parameter othernum is passed to the server side as num3. add3 is invoked like this:

<input type="button" onclick="javascript:add3(1);" value="plus 1" />  

Direct Call

THe above example has shown a direct calling, and it's the same with calling a normal JavaScript method:

 $(function () {

Call By Async Property

JQueryElement controls can invoke the generated methods by Async property:

<je:Button ID="cmdSub" runat="server" IsVariable="true"
 Label="sub" Disabled="true"

Using AjaxManagerID to specify the AjaxManager which contains the JavaScript method that you want to call, specify the JavaScript method name by ClientFunction.

Implicit Parameters

Part of the JQueryElement control will add the parameters to AjaxManager, such as the Repeater can add the pageindex, pagesize, etc.:

<je:Repeater ID="repeater" runat="server"
 FillAsync-AjaxManagerID="manager" FillAsync-ClientFunction="fill">

<je:AjaxManager ID="manager" runat="server">
  <je:AjaxSetting ClientFunction="fill" ClientParameter="othernum"
  ... >

The method fill does not add any Parameter, but property FillAsync will call the method fill, so the fill method is implicitly added pageIndex and pagesize.

Related Content



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralNicely writtena & useful Pin
sudhansu_k12319-Dec-11 21:50
membersudhansu_k12319-Dec-11 21:50 
GeneralRe: Nicely writtena & useful Pin
zoyobar26-Dec-11 14:51
memberzoyobar26-Dec-11 14:51 
GeneralMy vote of 4 Pin
Monjurul Habib12-Dec-11 10:55
memberMonjurul Habib12-Dec-11 10:55 
GeneralRe: My vote of 4 Pin
zoyobar26-Dec-11 14:50
memberzoyobar26-Dec-11 14:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170326.1 | Last Updated 26 Dec 2011
Article Copyright 2011 by zoyobar
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid