Friday, August 15, 2008

AJAX call within the same page

There is a way you can trick the code behind on an aspx page into believing it's a web service.

Example

First set up your code behind like so:


using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.Services;

namespace PostAuthenticateRequestModule
{
public class SignOut : Page
{

[WebMethod]
public static string GetServerTime()
{
return DateTime.Now.ToString();
}
}
}

And then your ASPX page goes something like this:

No comments:

Fixes to common .NET problems, as well as information on .NET features and solutions to common problems that are not language-specific.

Fixes to common .NET problems, as well as information on .NET features and solutions to common problems that are not language-specific.

Z