Current filter:
                                You should refresh the page.
                                Support Center
                                8
                                  • While you are using DX controls, the following questions may arise:

                                    1. What are callbacks? What is the difference between the ASPxCallbackPanel and asp:UpdatePanel?
                                    2. Why isn't the ViewState updated during a DX (e.g., ASPxGridView) callback?
                                    3. Why isn't the PreRender event raised on callbacks?
                                    4. How to make the controls operate in standard Postback mode?
                                    5. How to update an external control’s data during a callback to another control?
                                    For example:
                                              - I have two ASPxGridView controls. How do I refresh the second grid when the focused row within the first grid is changed?
                                              - How to refresh a master grid when a detail grid has been updated?
                                              - In the ASPxLabel, I need to reflect that the ASPxTreeList has been switched to Edit mode. How to do this?
                                              - When I click a button, the ASPxCallbackPanel refreshes a part of the page. How do I disable the button after a callback?
                                    6. Is it possible to send several simultaneous callbacks?
                                    7. Why aren't my custom scripts executed either during or after a DX callback?

                                    and many other...

                                    This Knowledge Base article describes how to resolve these issues and provides information on the callback nature.

                                • Nelson Rivers 3 10.21.2014

                                  What is the order of execution when using callbacks ?
                                  I'm trying to execute client-side javascript code & C# server-side code through an ASPxCallbackPanel control.  
                                  Expecting:
                                                      1.   BeginCallback="function( ) { lp.Show( );"
                                                      2.   OnCallback="CallbackPanel_Callback"
                                                      3.   EndCallback="function( ) { lp.Hide( );"

                                  The OnCallback code is being executed, but I think the BeginCallback & EndCallback is not possibly.

                                • Luke (DevExpress) 10.21.2014

                                  Hello Nelson,

                                  To process your recent post more efficiently, I created a separate ticket on your behalf: T163793: ASPxCallbackPanel - The BeginCallback and EndCallback events aren't raised. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

                                  Best Regards,
                                  Luke

                                1 Solution

                                Creation Date Rating Importance Sort by
                                26

                                1. What are callbacks? What is the difference between the ASPxCallbackPanel and asp:UpdatePanel?

                                Standard ASP.NET controls do not use callbacks, and all their internal processing is performed via postbacks only. This approach is good when page content is simple, so a browser can download the light page and render it quickly. However, when websites contain many heavy-weight controls, this approach is not suitable, because it might reduce page performance. When the Microsoft Atlas (ASP.NET AJAX) framework was introduced, a new UpdatePanel control was provided. This control intercepts postbacks that occur within a page and converts them to asynchronous postbacks. During an asynchronous postback, AJAX only renders a panel that initiated the postback, for example, if you have three asp:UpdatePanel controls, and one of them causes the postback, only this panel will be rendered.

                                Callbacks differ from asynchronous postbacks even if they provide almost the same results (in case of callbacks, only a part of a page is refreshed).

                                The main difference is how the ASP.NET page life cycle changes based on whether postbacks and callbacks are used. When a postback/callback occurs, ASP.NET builds a page from scratch by raising the following events: Page_Init and Page_Load. Between these events, the ViewState and post data (Postback Data) are loaded. During a callback, a control (that is "in callback" state) raises the callback event and then obtains the callback result.

                                The callback result always contains a part of a page (HTML tags, scripts, styles, etc.) - the part that was updated. As compared with the AJAX behavior, the callback result is very similar to what asp:UpdatePanel returns from the server when an asynchronous postback is processed. Since the page life cycle during callbacks is shorter than during postbacks, you should always remember that ViewState isn't updated on callbacks, as well as the PreRender event isn't raised on callbacks either.

                                These two points aren’t usually taken into account when a user moves from the asp:UpdatePanel controls to ASPxCallbackPanel ones.


                                2. Why isn't the ViewState updated during a DX (e.g., ASPxGridView) callback?
                                The ViewState data is contained in a special hidden field in a page markup. This hidden field data is posted to the server on any postback (a full page postback or callback). A full postback result contains the entire page markup (including the ViewState) even if a small part of the page is refreshed. A callback result contains only the markup of a callback sender and its children. There is no ViewState data in the callback result. Such an approach allows you to greatly reduce the rendered result, but the ViewState is not updated during a callback and is almost useless.

                                 
                                3. Why isn't the PreRender event raised on callbacks?

                                The PreRender event is not called during the callback due to design that is implemented in the System.Web.UI.Page.ProcessRequestMain method.

                                 
                                4 How to force the controls to work in the standard Postback mode?

                                Most of complex DevExpress ASP.NET controls, such as ASPxGridView, ASPxTreeList, ASPxPivotGrid, use their own callbacks (since the EnableCallBacks property equals "true") to update their own rendering during a round-trip to the server, which is intended to change a corresponding control's state.

                                It is, however, possible to disable controls' callbacks by setting the EnableCallBacks property to "false" to force the controls to work in standard postback mode (in the same manner as the standard controls work) and put the controls, for example, into the UpdatePanel, (as it is illustrated in the ASP.NET AJAX - Update Panel online demo), so that the controls can work with MS AJAX/ControlToolkit.

                                 
                                5. How to update external control data during a callback to another control?

                                During a partial update, the result obtained from the server contains HTML page markup, which will be placed in the updated area. For example, you have an ASPxButton, a label within the asp:UpdatePanel and a label outside the asp:UpdatePanel. On the button's click event, you want to update both labels. What will the result be? On the server side, two labels will be updated. However, as it is stated above, the result obtained from the server will have the ASPxButton and the first label. So, after a postback, you'll get the updated first label only.

                                This statement can be easily applied to the ASPxCallbackPanel: assume you have both the ASPxButton and a label outside the ASPxCallbackPanel, and a single label within the callback panel. The button has the ASPxButton.AutoPostBack property disabled, and the callback panel is refreshed using the ASPxClientCallbackPanel.PerformCallback method:

                                [JavaScript]
                                function OnClick (s, e) { callbackPanel.PerformCallback (); }

                                On the server side, both labels will be updated using the following ASPxCallbackPanel.Callback event handler:

                                [C#]
                                protected void callbackPanel_Callback(object source, CallbackEventArgsBase e) { lblInside.Text = "Inside"; lblOutside.Text = "Outside"; }
                                [VB.NET]
                                Protected Sub callbackPanel_Callback(ByVal source As Object, ByVal e As CallbackEventArgsBase) lblInside.Text = "Inside" lblOutside.Text = "Outside" End Sub

                                According to the declared statement, the content within the ASPxCallbackPanel will be updated. After a callback, you'll see the inner label updated, not the outer one.


                                These examples are simple, but they describe the main idea of partial updates. When other callback controls, such as ASPxGridView or ASPxTreeList are used, all these principles can be applied to them. Assume there is an ASPxGridView with a focused row turned on, and two labels on a page. One label is placed in the grid's Title Panel and the other one is placed outside the grid bounds. A user wants to refresh the labels in the server-side ASPxGridView.FocusedRowChanged event handler. What result will he or she get?

                                The label outside the grid bounds won't be updated. However, the label in the Title Panel will be. When a callback occurs, the ASPxGridView refreshes itself, changes the focused row index, and then modifies both labels. However, due to the callback, the grid renders itself (with a single refreshed label only) and sends the HTML page markup to the client side. After that, a user will see a single label being updated only.

                                These examples are in effect for multiple controls. For example, the following issues have almost the same explanation as the one described above:

                                1. There are two grids. On the server-side ASPxGridView.FocusedRowChanged event handler, the second grid gets refreshed. Why isn’t the second grid changed even though the code works fine?

                                This happens because the first grid sends a callback, and the callback result has only the grid that initiated the callback.

                                2. Why can't I change page layout in the ASPxComboBox.Callback event handler?

                                The event handler is able to change the current combobox only. Most often it is used to bind the combobox with a datasource. It is impossible to change page layout of other controls.

                                3. Why does the ASPxCallback.Callback event handler update neither grids nor even a button? Is it a bug?

                                The ASPxCallback control is able to send callbacks to the server. It sends a string argument and returns a string result. The control doesn't refresh a page. Use the ASPxCallbackPanel instead.

                                4. I have a master-detail grid on the page. The master grid shows the number of detail records in unbound columns. I want to refresh the master grid when a detail row is deleted. Why doesn't the DataBind method work in the ASPxGridView.RowDeleting event handler?

                                When a row is deleted, the detail grid sends a callback to the server. On its callback, it is possible to update the detail grid only. When you call the DataBind method of the master grid, the callback result doesn't contain the updated layout. That is why you can update the detail grid, but not the master one.

                                All these and similar issues have an explanation of why they occur. However, there are many solutions that can be easily implemented even when callbacks are used:

                                1. A general solution for all these tasks is to turn off callbacks. Of course, a control won't work using the callbacks technology, but as an entire page is refreshed, it will be possible to do whatever is required. To avoid unnecessary postbacks, it is useful to wrap required controls in the asp:UpdatePanel.

                                2. Usually, it is enough to replace server-side code with its client-side equivalent. As DevExpress ASP.NET controls support Client-Side Functionality, it is better (and faster) to update/refresh controls on the client side:

                                For example, the mentioned labels can be updated using the client-side ASPxClientGridView.FocusedRowChanged event handler and the ASPxClientLabel.SetText method:

                                [JavaScript]
                                function OnFocusedRowChanged (s, e) { lblInner.SetText("Inner"); lblOuter.SetText("Outer"); }

                                Note: usually it is useful to prevent the server-side data processing by adding the "e.processOnServer = false;" line into the JavaScript event handler (please check the appropriate documentation before writing this line; maybe, the "e" argument doesn't have this property).

                                3. If a page is simple, and server-side code is executed fast, you can refresh controls by sending several subsequent callbacks. For example, if you wish to refresh the master grid, you can use the ASPxClientGridView.Refresh method. All you need to know is when this method should be called. Of course, it should be called when the detail grid callback ends (ASPxClientGridView.EndCallback). However, since the detail grid can send different callbacks (e.g., when it is sorted, paged, filtered, etc.), the master grid will always be refreshed on every detail grid callback. To avoid this, you should "tell" a client-side object when the Refresh callback should be sent using the JSProperties:

                                [C#]
                                protected void detailGrid_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) { ASPxGridView detailGrid = sender as ASPxGridView; detailGrid.JSProperties["cpDelete"] = true; }
                                [VB.NET]
                                Protected Sub detailGrid_RowDeleting(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataDeletingEventArgs) Dim detailGrid As ASPxGridView = TryCast(sender, ASPxGridView) detailGrid.JSProperties("cpDelete") = True End Sub
                                [JavaScript]
                                function OnDetailGrid_EndCallback (s, e) { if (s.cpDelete) { delete s.cpDelete; masterGrid.Refresh(); } }

                                In the EndCallback event handler, you can perform any necessary actions: show popups, update editors, implement cascading behavior, etc.

                                Usually, it is useful to determine the moment when a callback starts and ends. For such purposes, two event handlers are used: BeginCallback and EndCallback. All controls supporting callbacks are able to raise the events. These events are useful when you wish to determine the type of a callback by using the e.command attribute, or when you need to show and hide the ASPxLoadingPanel.

                                Sometimes, it might be useful to have a general callback handler: the ASPxGlobalEvents control. This is an invisible control that raises the same BeginCallback and EndCallback events when any control on a page initiates a callback.

                                You will find more examples below:

                                The concept of callbacks - Why is it impossible to update external control data during a callback to another control
                                ASPxGridView - How to refresh a master grid when a detail grid has been updated

                                 
                                6. Is it possible to send several simultaneous callbacks?

                                We advise against sending parallel (or simultaneous) callbacks to controls that might use each other during (or after) a callback. What does it mean? Let's assume that you have three ASPxGridView controls and wish to refresh them all:

                                [JavaScript]
                                grid1.Refresh(); grid2.Refresh(); grid3.Refresh();

                                This code should work fine, because three grids might not depend on each other. For example, when the first grid is updated, it uses its own data source, the second grid uses its own, and so on. However, if you want to change some values on the first grid's callback, and then read them on the second grid's callback, this approach will require additional coding. We call this scenario a "callbacks rush":

                                When the first callback is sent, the server starts to update the page by raising appropriate events. At the same time, the client-side version of the page still exists, and its next JavaScript line sends another callback. The server is a multi-thread system, and one of its threads may complete faster than another. There is nothing unusual about this, because if the first callback uses more data than the second one, you'll get the second result faster than the first.

                                To avoid this and similar situations, it is recommended to send subsequent callbacks. They function in the following way: the first callback is sent, and we wait until its result becomes available (in the EndCallback event handler). When the event is raised, the second callback is sent. When the second callback ends, the third callback is sent, and so on. Approximate code will be the following:

                                [JavaScript]
                                ... grid1.PerformCallback(); } function OnGrid1_EndCallback (s, e) { grid2.PerformCallback(); } function OnGrid2_EndCallback (s, e) { grid3.PerformCallback(); } ...


                                There is another scenario when several parallel callbacks may not work. If you use the Session state, it blocks parallel execution and forces parallel requests to be executed one after another. The reason is because access to the ASP.NET Session state is exclusive per session. You will learn more about this specific in the following KB article:

                                KA18599: How to perform parallel callbacks to get some information about server-side process

                                 
                                7. Why aren't my custom scripts executed during or after a DX callback?

                                By design, external scripts are not evaluated on DevExpress callbacks. There is no universal way of evaluating third-party control scripts on DevExpress callbacks. In some cases, scripts should not be evaluated, because they are loaded twice. It is impossible to track such situations on our side. Therefore, every case requires an individual approach. Below you will find most commonly encountered cases.

                                - To execute your own script after a callback performed by a DevExpress control, use a specific "dxss_" or dxis_" prefix. The following KB articles describe how to use these prefixes and the difference between them:

                                KA18783: How to register JavaScript on DevExpress callbacks

                                - Sometimes, you may place a script block outside a callback control (e.g. ASPxCallbackPanel) and assign script handlers to client events of controls placed within the callback control. In this case, the execution context differs from the context where methods were searched after a control callback. To get the desired result, assign the methods to the global 'window' object as described below:

                                Q350828: ASPxPageControl - Script methods registered on new tab activating are unavailable after a callback sent by the child ASPxCallbackPanel

                                However, in some cases, these approaches may lead to unexpected results, since scripts are processed asynchronously, and there can occur a situation when the script to be executed isn't processed yet.

                                So, we suggest that you move all client-side code, which should be used in your custom control, to an external *.js file, and attach this file to a main ASPX page. This way, everything should work fine.

                                 
                                Afterword:

                                Callbacks are interesting and quite helpful as compared to asynchronous postbacks. Unfortunately, in solving many issues that occurred in real projects, the callback nature wasn’t taken into account. If under certain conditions, a project doesn't work correctly with enabled callbacks, simply disable them and try to solve the task using UpdatePanel controls only. After that, you can use a similar solution with callbacks again.

                                Show all comments
                                • Roger Osborn 12.18.2012

                                  Great article. Thanks. This explains what I've been struggling with for days now. Wish I had seen it sooner.

                                • Anton Liakishev (old) 01.26.2013

                                  Really Great! Thanks.

                                • JORGE MALDONADO 05.16.2013

                                  Very interesting and useful information. I rely very heavily on callbacks and this article shows how to make use of such technology efficiently.

                                • Huy Phan 3 07.09.2013

                                  Thank Vest a lot. This article saved my life.

                                • Vlаd 10.30.2013

                                  Vest, your article is the best!!!

                                • Anthony (DevExpress Support) 12.23.2013

                                  I've created the Popup with Dynamic Data ticket to discuss this issue. Please refer to it.

                                • Luciano Oliveira 2 01.15.2014

                                  Very good article Mr. Vest.
                                  Now I fully understand why sometimes, when calling a callback from DevExpress, the data from other controls are not updated.
                                  But this leads me to a question:

                                  Like you've said, the view state is not updated in callbacks. Many times, when we go to server-side (like callbacks or postbacks), we have to process and update data in the view state and so on. How could we use callbacks in these cases instead of async postbacks (updatePanel)?

                                  Regards

                                • Hi

                                  I created a new thread to discuss your question. Please refer to the following link:

                                  Q25865

                                • Yilmaz Uksal 09.24.2014

                                  How about like methods such as ASPxClientGridView.UnselectRows()? It causes a call back, but it doesn't update grid's data? Since callbacks cause Page_Load to execute and UnselectRows causes a call back, then why UnselectRows doesn't update grid data? Are there special cases with client side methods of the grid?

                                • Luke (DevExpress) 09.24.2014

                                  Hello,

                                  To process your recent post more efficiently, I created a separate ticket on your behalf: T154430: How ASPxClientGridView methods that send a callback work. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

                                • Nick Hoare 02.02.2015

                                  Is this statement still ccorrect? "During an asynchronous postback, AJAX only renders a panel that initiated the postback, for example, if you have three asp:UpdatePanel controls, and one of them causes the postback, only this panel will be rendered." ?

                                  The UpdatePanel documentation states:
                                  "If the UpdateMode property is set to Always, the UpdatePanel control's content is updated on every postback that originates from anywhere on the page. This includes asynchronous postbacks from controls that are inside other UpdatePanel controls and postbacks from controls that are not inside UpdatePanel controls"

                                  I have successfully used multiple update panels and had them all update when a control inside one causes a postback.  Can an AspxCallBackPanel be used to replicate this  behaviour?

                                • Hello,

                                  To process your recent post more efficiently, I created a separate ticket on your behalf: T203879: ASPxCalbackPanel - How to replicate the UpdatePanel behavior. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

                                • Patrik Johansson _ 04.07.2016
                                  Hi,

                                  Reading through this post and it's comments, one question keeps popping into my mind, what are the advantages that a Callback has compared to asynchronous postbacks (UpdatePanel) and when would it be better to use the Callback compared with the asynchronous postbacks? Please provide some real life scenarios and not just theoretical ones. Thank you.

                                  Regards,
                                  Patrik Johansson

                                • Hello Patrik,

                                  I see that you asked this question in DevExpress equivalent of Teleriks RadAjaxManager/RadAjaxPanel. Let's continue our conversation there.
                                • antoni levano 11.24.2016
                                  good explanation ! man

                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2017 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners