29 December 2011

Page Methods in asp.net



Now a days, People are looking for richer user experience, In short what they need is more speed or we can say in simple terms, Now a days people dont like waiting.

Ajax is the one by which we can create such applications
In asp.net several methods are there for calling Server Side function from JavaScript and Page methods introduced in 2.0 is one of them.

Requirements for creating Page Methods
1.It has to be static
2.It must have attached attribute WebMethod.

Example.

Lets Create a small Web application say "CallServerFunction" which contain a web page say "MyDateTimeClass"


CodeBehind
using System;
using System.Web.Services;
namespace MarlaLibraries.PageMethods
{
 public partial class PageMethodTest : System.Web.UI.Page
 {
  [WebMethod]
  public static string GetUniqueId()
  {
   return Guid.NewId.ToString();
  }
 }
}
Aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PageMethodTest .aspx.cs" Inherits="MarlaLibraries.PageMethods.Test" %>

  . 
  .
  . 
  .
  
. . .
Javascript
 
That’s it as you see it’s very easy.Hope you like it. Stay tuned for more.Till then Enjoy Programming..

Things are upgraded

My Dear readers, I am really thankful for being supportive all these years. This site was the first blog site I ever created in my life...