[English Reading Notes] using page methods in ASP. NET Ajax

Source: Internet
Author: User
ArticleDirectory
    • Our "Contact Us" form in ASP. NET
    • Our PAGE method exposed to ASP. NET Ajax

Address: http://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx
Author:Timothy Khouri

According to the title, it is easy to think of PAGE method call in the updatepanel method, but this article refers to the method of asynchronous WebService call on the client. It also uses very conciseCodeTo describe the calling method.

The author uses a contact us page to describe.

First, create a form:

Our "Contact Us" form in ASP. NET < Form Runat = "Server" >
< ASP: scriptmanager ID = "Scriptmanager" Runat = "Server"
Enablepagemethods = "True" />
< Fieldset ID = "Contactfieldset" >
< Label >
Your name
< Input Type = "Text" ID = "Nametextbox" /> < /Label >
< Label >
Email Address
< Input Type = "Text" ID = "Emailtextbox" /> < /Label >
< Label >
Your message
< Textarea ID = "Messagetextbox" > < /Textarea> </label >
< Button Onclick = "Sendform ();" >
Send < /Button >
< /Fieldset >
< /Form > Then the WebService File

Our PAGE method exposed to ASP. NET AjaxUsingSystem;
UsingSystem. Web. Services;

PublicPartialClassContactus: system. Web. UI. Page
{
[Webmethod]
Public Static VoidSendform (StringName,StringEmail,StringMessage)
{
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 .");
}

// If weGet ThisFar we know that they entered enough data, so
// HereIsWhere you wocould send the email or whatever you wanted
//Do
}
}

Finally, the JavaScript to be called in the Form file

FunctionSendform (){
VaRName = $ get ("Nametextbox"). Value;
VaREmail = $ get ("Emailtextbox"). Value;
VaRMessage = $ get ("Messagetextbox"). Value;

Pagemethods. sendform (name, email, message,
Onsucceeded, onfailed );
}

FunctionOnsucceeded (){
// Dispaly"Thank you ."
$ Get ("Contactfieldset"). Innerhtml ="<P> thank you! </P>";
}

FunctionOnfailed (error ){
// Alert user to the error.
Alert (error. get_message ());
}

All things are described by the original author. It turns out to be so simple.

Related Article

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.