In this article we will learn how to use PageMethods in or what is PageMethods in or why use PageMethods in or Call PageMethods using ASP.Net AJAX and ScriptManager with example.


ASP.Net AJAX ScriptManager enable to you to call Server Side methods from client side without page PostBack using PageMethods. The server side methods should be public and static and  These method should be WebMethod() attribute.

ScriptManager  Enabling PageMethods:

The first step you need to do is add a ASP.Net AJAX ScriptManager to the page and set its EnablePageMethods property to true as shown below:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">




Client Side Code:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PageMethod.aspx.cs"
Inherits="AspDotNet.PageMethod" %>
<!DOCTYPE html>
<html xmlns="">
<head runat="server">
    <script src="Content/Scripts/jquery-1.8.2.min.js"></script>
    <script type="text/javascript">
        function ShowUserID() {
        function OnSuccess(response) {
    <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"
                Your Name :
                <asp:TextBox ID="txtUserName" runat="server" Width="200">
                <input id="btnGetUserName" type="button" value="Show My UserID"
                  onclick="ShowUserID ()" />
                <br />
                <br />
                Your UserID:
                <asp:TextBox ID="txtUserID" runat="server" disabled Width="200">


Server Side Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AspDotNet
    public partial class PageMethod : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
        public static string GetUserID(string name)
            return  name + "Your Id Is EMP0001245";


Above Example ShowUserID method makes an AJAX call to the server using ASP.Net AJAX ScriptManager PageMethods and executes the GetUserID method which accepts the username and returns a string value.




How to use PageMethods in Asp.Net

I hope this article will help to you.

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like