DataWindow .NET context management

The context management system used by DataWindow .NET is similar to ASP.NET’s ViewState management; however, it uses a context model to maintain and manage changes in data on both the client and server and to manage the state of its data on a page round trip. The context includes changes in data on the server, including data modification, rows inserted, and rows deleted, as well as changes in data on the client and additional state information. It does not contain all the data in the DataWindow—only the changes made to data.

To use the Web DataWindow context management system, you must set EnableDataState to true.

Context management process

Context is managed as follows:

  1. When the initial page request is made, the DataWindow retrieves data. A user can then perform any operation on the DataWindow.

  2. When the control is rendered, the DataWindow engine generates an encoded context string that contains changes to data, such as the modification of existing data and rows inserted and deleted. This context string is stored in a hidden field and sent to the client with the rendered DataWindow.

  3. When the DataWindow displays in the browser, the user can make changes in the form on the page and then submit the page. Before the page is posted back to the server, the Web DataWindow client control collects the changes made in the browser and appends them to the original context string. The context string is passed back to the server.

  4. When the page is posted back, the server control gets the context from the hidden field as a server variable. After the DataWindow retrieves data, the context is restored to the DataWindow, either manually or automatically depending on the AutoRestoreContext property setting.

  5. When the user performs another operation on the DataWindow, the process is repeated.

NoteUpdate resets the context Changes in data on the server are cleared when the data is updated to the database, and the context string is reset.

Restoring context

You can set the AutoRestoreContext property to true (the default) to have the context restored to the DataWindow in the browser automatically before the user can make any changes to the DataWindow. Setting AutoRestoreContext to true calls the RestoreContext method implicitly.

NoteContext should not be restored until the DataWindow has data Context should only be restored after the DataWindow has obtained its data. This can be done using a retrieve, an import, a data cache restore, or another method.

If AutoRestoreContext is true and AutoRestoreDataCache is false, you should populate the DataWindow's data before the WebDataWindowControl's OnLoad event. In this case, the best place to populate the DataWindow with data is in the OnLoad event for the page. For example, you can call Retrieve in the page's OnLoad event and set AutoRestoreContext to true to let the DataWindow automatically restore its context. If you do not want to conform to this limitation, you can set AutoRestoreContext to false and then call the RestoreContext method manually after your data retrieve is done.

If you need to restore context manually, use the RestoreContext method explicitly. If context is not restored correctly when the AutoRestoreContext property is set, an AutoRestoreContextError event is triggered. A failure in the RestoreContext method throws an exception.

Data state

There are times when it is appropriate to disable the data state, particularly to improve application performance. For example, if you import a large amount of data into a WebDataWindowControl, the state of data changes becomes large because all the rows imported are treated as newly inserted rows. (In a retrieve, only new rows are added to the data state of changes.)

If the EnableDataState property is set to true, importing a large amount of data sends a large context to the client. When the page is posted back, there is no need to import the data again since the context containing the state of data changes is restored to the WebDataWindowControl. If you want to improve performance, you can avoid sending a large context to the client by setting EnableDataState to false. However, since with this setting the imported data is not included in the context, you must import the data again when the page is posted back.