ASP.net 2.0 implements no flush client callback

Source: Internet
Author: User

Asp.net2.0 's client callback is a very exciting way to let us control what data is submitted to the server without submitting the entire page, and the server simply returns the data you need instead of sending it back to the entire page.

First of all, we have to say a very important method: Getcallbackeventrefernce. I write my understanding out, may be wrong, please point out, thank you very much!

GetCallbackEventReference first realizes that the client script has the ability to pass parameters to the server-side RaiseCallbackEvent method, and then returns the value of the RaiseCallbackEvent method to you in A parameter that is registered in the Getcallbackeventrefernce method (it is also a script that you want to write on the client). Call getcallbackeventrefernce You must pass the client script to him two parameters, one is to pass to the RaiseCallbackEvent event value, one is the context.

The meaning of his argument is as follows:

First: a page or server control that implements the ICallbackEventHandler excuse, and writes this to the front page.

Second: Represents the value that you want to pass from the client to the server RaiseCallbackEvent method

Third: You want to write a JS function on the client, at the same time, the server will also pass the computed data to the function as the parameter of this function.

Fourth: Context specific what meaning I am not very clear getcallbackeventrefernce sent to the customer, the end of the code is like this:

WebForm_DoCallback ('__Page',arg,ReceiveServerData,context,null,false)

So what can we do to call him from the client? See the three-way method:

The first: Write a public string in the background and assign the value to him in the Page_Load: =page.clientscript.getcallbackeventreference (this, "message", " Showservertime "," context ") Note that this is page.clientscrip because he will return a Clientscriptmanager,clientscriptmanager client script. Then <%= the public background string in the OnClick event of a button in the foreground%> do a little experiment code as follows:

Front desk servertime.aspx: In order to easily remove a lot of useless html

<%@ page language="C#" CodeFile="ServerTime.aspx.cs" Inherits="ServerTime_aspx" %>
<title>Server Time</title>
<script language="javascript">
function GetServerTime()
{
  var message = '';
  var context = '';
  <%=sCallBackFunctionInvocation%>
}
function ShowServerTime(timeMessage, context) {
  alert('现在服务器上的时间是:\n' + timeMessage);
}
</script>
<body>
<form id="MainForm" runat="server">
<input type="button" value="得到服务器端时间" onclick="GetServerTime();" />
</form>
</body>

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.