Asp.net Ajax Learning 1

Source: Internet
Author: User
<% @ 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 .. ,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.