-
The page code runs on the server, and a new version of the page is rendered to the browser.
-
Post back introduce processing overhead that can decrease performance.
-
If the client script in the page is maintaining some state information (local variable values), posting the page and getting a new copy of it destroys that state.
The popular Solution:
Use AJAX Update Panel to post back only the control inside Update Panel:
Update Panel Advantages:
-
Partial-Page Rendering.
-
Partial-page updates support.
-
Remove the requirement to refresh the whole page with each post back, which improves the user experience.
Using Update Panel:
-
Drag /Drop Script Manager on your web page.
-
Drag / Drop Update Panel.
-
Drag / Drop GridView Data Control inside the Update Panel.
The Problem with using this popular Solution:
-
The web page size is over optimum size, when using ScriptManager.
-
The Update Panel store huge view state size for it and its content.
The Best Solution is:
"Implementing Client Callbacks Programmatically without Post Back"
Examples of client callbacks:
Several Web server controls use client callbacks. For example, the Tree View control uses client callbacks to implement it’s populate on demand functionality.
Get started: Follow me:
1- Implement the ICallbackEventHandlerinterface:
public partial class _Default : System.Web.UI.Page,ICallbackEventHandler
{
This interface provide the following 2 methods:
- Aspx.cs Code:
- RaiseCallbackEvent method: This method will be invoked to perform the callback on the server.
- GetCallbackResult method: This method will return the callback result to the client.
private string _callbackArg;
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
_callbackArg = eventArgument;
}
string ICallbackEventHandler.GetCallbackResult()
{
return RaiseCallbackEvent(_callbackArg);
}
- Aspx.cs Client Side Code:
- Page.ClientScript.GetCallbackEventReference: the helper function that performs the actual request to the server, which is generated automatically by ASP.
- Aspx Client Side code (client callback function):
- This function receives the result from the server code that processed the callback event, accepting a string that represents the results:
<script type="text/javascript">
function RateContent(result, context)
{
document.getElementById('Result').innerHTML = result;
}
</script>