<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Default. aspx. CS " Inherits = " _ Default " %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.1 // en" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head Runat = "Server" >
< Title > Untitled page </ Title >
< Script >
Function Sendform () {
VaR Name = $ Get ( " Nametextbox " ). Value;
VaR Email = $ Get ( " Emailtextbox " ). Value;
VaR Message = $ Get ( " Messagetextbox " ). Value;
Pagemethods. sendform (name, email, message,
Onsucceeded, onfailed );
}
Function Onsucceeded () {
// Dispaly "thank you ."
$ Get ( " Contactfieldset " ). Innerhtml = " <P> thank you! </P> " ;
Window. Location = " Http://www.csdn.net " ;
}
Function Onfailed (error) {
//Alert user to the error.
Alert (error. get_message ());
}
</ Script >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< ASP: scriptmanager ID = "Scriptmanager1" Runat = "Server" />
< Fieldset ID = "Contactfieldset" >
< Label >
Your name
< Input Type = "Text" ID = "Nametextbox" /> </ Label > < HR />
< Label >
Email Address
< Input Type = "Text" ID = "Emailtextbox" /> </ Label > < HR />
< Label >
Your message
< Textarea ID = "Messagetextbox" > </ Textarea > </ Label >
< Button Onclick = "Sendform ();" >
Send </ Button >
</ Fieldset >
</ Form >
</ Body >
</ Html >
Using System;
Using System. Data;
Using System. configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. Web. UI. htmlcontrols;
Using System. Web. Services;
Public Partial Class _ Default: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
}
[Webmethod]
Public Static Void Sendform ( String Name, String Email, String Message)
{
If ( String . Isnullorempty (name ))
{
Throw NewException ("You must supply a name.");
}
If ( String . Isnullorempty (email ))
{
Throw NewException ("You must supply an email address.");
}
If ( String . Isnullorempty (Message ))
{
Throw NewException ("Please provide a message to send.");
}
}
}
It seems pretty good to use it.
Transferred from
Http://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx
Pagemethods
It seems that only static methods can be called later .. ,