Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.








Sys.Net.PageMethod Sample


<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Services" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">

    // Get session state value.
    public static string GetSessionValue(string key)
        return (string)HttpContext.Current.Session[key];

    // Set session state value.
    public static string SetSessionValue(string key, string value)
        HttpContext.Current.Session[key] = value;
        return (string)HttpContext.Current.Session[key];


<html xmlns="">

<head id="Head1" runat="server">

    <title>Using Page Methods with Session State</title>
    <style type="text/css">
            body {  font: 11pt Trebuchet MS;
                    font-color: #000000;
                    padding-top: 72px;
                    text-align: center }
            .text { font: 8pt Trebuchet MS }


    <h2>Using Page Methods with Session State</h2>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" 
            runat="server" EnablePageMethods="true">
                <asp:ScriptReference Path="PageMethod.js"/>

            <tr align="left">
                <td>Write current date and time in session state:</td>
                    <input type="Button" 
                        onclick="SetSessionValue('SessionValue', Date())" 
                        value="Write" />
            <tr align="left">
                <td>Read current date and time from session state:</td>
                    <input type="Button" 
                        value="Read" />
    <span style="background-color:Aqua" id="ResultId"></span>