By default web forms are stateless meaning that when a Web server receives a request for a page, it finds the page, processes it, sends it to the browser, and then, effectively, discards all page information. If the user requests the same page again, the server repeats the entire sequence, reprocessing the page from scratch. In other words the server has no memory of pages that it has processed. This can be a significant limitation especially when your server side code contains computationally expensive or memory consuming code.
For example suppose that you have a server side form querying a database and populating a chart. If the contents of the database does not change frequently it is not feasible to execute a code producing the same result over and over every time the server receives a request. In such cases you may consider using the ability of the control to persist its state.
There are two major strategies to make a persistent Nevron Chart server control. The first one is to store the control state on the server and second one is to store the control state on client in the view state of the form. This is how it works:
- When the page is processed the control stores its state in the repository specified in the Repository property of the NControlStateSettings object.
- When the client browser requests the page again (postback) the control reads the saved state from the repository.
To enable persistency of the control state across roundtrips you have to set the PersistControlState property to true:
C# |
Copy Code
|
//[theComponent] is the name of the Nevron component - being it a Chart or a Diagram
[theComponent].ServerSettings.ControlStateSettings.PersistControlState = true;
|
Visual Basic |
Copy Code
|
'[theComponent] is the name of the Nevron component - being it a Chart or a Diagram
[theComponent].ServerSettings.ControlStateSettings.PersistControlState = True
|
By default the control will use server side persistency meaning that the control state repository will save and load the state from the server. This approach reduces the amount of traffic between the client and server. The drawback is that the server may decide to clean up the saved state if it expires. Therefore if you expect that the client will not refresh the content of the control frequently you must use the client side repository:
C# |
Copy Code
|
//[theComponent] is the name of the Nevron component - being it a Chart or a Diagram
[theComponent].ServerSettings.ControlStateSettings.Repository = new NViewStateRepository();
|
Visual Basic |
Copy Code
|
'[theComponent] is the name of the Nevron component - being it a Chart or a Diagram
[theComponent].ServerSettings.ControlStateSettings.Repository = New NViewStateRepository()
|
If you want to revert to the server repository you must use:
C# |
Copy Code
|
//[theComponent] is the name of the Nevron component - being it a Chart or a Diagram
[theComponent].ServerSettings.ControlStateSettings.Repository = new NServerRepository();
|
Visual Basic |
Copy Code
|
'[theComponent] is the name of the Nevron component - being it a Chart or a Diagram
[theComponent].ServerSettings.ControlStateSettings.Repository = New NServerRepository()
|
Finally you should know that you can apply serialization filters to the content that is actually stored on the client or the server. For more information please take a look at the topic describing serialization in detail. The following example configures the chart to persists it's data settings only:
C# |
Copy Code
|
//[theComponent] is the name of the Nevron component - being it a Chart or a Diagram
[theComponent].ServerSettings.ControlStateSettings.PersistencyFormat = PersistencyFormat.CustomXML;
[theComponent].ServerSettings.ControlStateSettings.SerializationFilter = new NDataSerializationFilter();
|
Visual Basic |
Copy Code
|
'[theComponent] is the name of the Nevron component - being it a Chart or a Diagram
[theComponent].ServerSettings.ControlStateSettings.PersistencyFormat = PersistencyFormat.CustomXML
[theComponent].ServerSettings.ControlStateSettings.SerializationFilter = New NDataSerializationFilter()
|