DevExpress Asp.net (3) ASPxCallback component

Source: Internet
Author: User

The ASPxCallback control encapsulates a large number of Ajax operations for us, which is very convenient to use. If you encounter operations that require partial refreshing on the page and do not want to write ajax automatically, it is a good choice. ASPxCallback mainly registers client events and server events to communicate with each other to complete the task.

How to Use ASPXCallback:

  1. Add the CallBack component to the page and set the ClientInstanceName attribute (Client ID, for example, ClientInstanceName = "Callback1 ").
  2. Register the server-side event ASPxCallback_Callback of the CallBack component. This method is the server-side processing program that the client will call.
  3. Register the CallbackComplete event of the CallBack component. The cited event is automatically called after the server event is called back. It can be used to process the operations after the CallBack, you can also use parameter e to obtain the parameter value and set the returned result value.
  4. Call the CallBack mcallback method of the client user CallBack component to call the ASPxCallback_Callback event of the server.
    Code: Callback1.PerformCallback (id)
  5. The CallBack component automatically calls the CallbackComplete event to complete this operation.

 

The following example shows how to use the client to enable the server to update the data in the DIV.

HTML code
Each DIV has a <a/> label. You can call the Javascript function ShowDetails to update the content of the DIV. The parameter is the last number of the div id. The ASPxCallback component registers the server's OnCallback event to process the callback. The ClientSideEvents CallbackComplete method is automatically called when the callback is complete.
JS. Call the OnCallback event of the server through Callback1.PerformCallback (id ).

Code
<Script type = "text/javascript"> <! --
Function GetDetailsContainer (id ){
Return document. getElementById ("Detail" + id. toString ());
}
Function ShowDetails (id ){

GetDetailsContainer (id). innerHTML = "Loading & hellip ;";
Callback1.PerformCallback (id); // Callback method. The Callback method registered on the server is called.
}

// --> </Script>

HTML:

Code
<Div id = "Detail1">
<A href = "javascript: ShowDetails ('1');"> Show Detail </a>
</Div>
<Div id = "Detail2">
<A href = "javascript: ShowDetails ('2');"> Show Detail </a>
</Div>
<Div id = "Detail3">
<A href = "javascript: ShowDetails ('3');"> Show Detail </a>
</Div>

<Dxcb: ASPxCallback ID = "ASPxCallback1" runat = "server" ClientInstanceName = "Callback1"
OnCallback = "ASPxCallback1_Callback">
<ClientSideEvents CallbackComplete = "function (s, e ){
Var element = GetDetailsContainer (e. parameter );
Element. innerHTML = e. result;
} "/>
</Dxcb: ASPxCallback>

<! --
-------------------------------------------------
CallbackComplete method prototype:
Function ASPxClientCallbackCompleteEventHandler (
Source: object,
E: ASPxClientCallbackCompleteEventArgs
): Void;
Parameter: Get the parameter value of AspxCallBack for callback.
Result: gets the result value after the callback.

This method is automatically called after the callback is complete.
------------------------------------------------
-->

C #, In the OnCallback event, accept the parameters passed by the client to determine which DIV is updated, and return the processed Result through e. Result:

Code
Protected void ASPxCallback1_Callback (object source, CallbackEventArgs e)
{
Switch (e. Parameter)
{
Case "1 ":
E. Result = "win in the distributed development of WCF (1): basic concept of the distributed framework ";
Break;
Case "2 ":
E. Result = "win in the distributed development step of WCF (2) Detailed description of the custom hosted host WCF solution development and configuration process ";
Break;
Case "3 ":
E. Result = "WCF distributed development step to win (3) WCF Service metadata exchange, configuration and programming development ";
Break;
}
}

Finally, all client callbacks of the Aspx control are implemented through this module. For example, you can set the ClientInstanceName attribute of Aspx, add the Callback Method for registering the Aspx server, and call the Callback mcallback () of Aspx on the client () method. This mode will be frequently seen in future use.

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.