Innovation comes from understanding easy to build your own AJAX framework

Source: Internet
Author: User
Tags interface new features string client

This article is just a basic AJAX framework, although AJAX is not a new technology, but as a framework is not an article can explain the white. The purpose of this article: to help beginners learn better and use the AJAX framework.

I always believe that only if you really understand a technology and understand the technology itself can you use it better and more flexibly. A programmer's understanding of technology cannot be confined to the application of technology.

Environment: Window Xp SP2 +. Net framwwork 2.0.50727.

asp.net 2.0 self-brought client callback

ASP.net 2.0 has been released. 2.0 has many new features, and the client callback is one of them. The client callback allows us to invoke the server-side method without a postback, which is consistent with the functionality provided by Ajax, but not as flexible as Ajax, where Ajax can customize the calling method, with 2.0 of its own callback capabilities.

The System.Web.UI.IcallbackEventHandler interface must be implemented to use the client callback feature.

This interface contains two methods:

//客户端回调时固定调用此方法
public void RaiseCallbackEvent(String eventArgument)
//执行完RaiseCallbackEvent后将调用此方法。此方法的返回值将被发回客户端
public string GetCallbackResult()

Example one:

.cs:
String cbReference = Page.ClientScript.GetCallbackEventReference(this,"arg", "ReceiveServerData", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + "} ;";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"CallServer", callbackScript, true);
javascript:
<script type="text/javascript">
function LookUpStock()
{
 var product = "";
 var lb = document.forms[0].ListBox1;
 if(lb.selectedIndex >= 0)
product = lb.options[lb.selectedIndex].text;
CallServer(product, "");
}
function ReceiveServerData(rValue) { Results.innerText = rValue; }
</script>



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.