Glossary Item Box
HTTP applications are stateless applications, meaning that consecutive HTTP requests have no knowledge of each other. This makes it challenging to write a complex Internet application, since it is necessary for applications of this type to have information about other requests. Many techniques (such as cookies, session variables, querystring passing) have been used to add state to HTTP. ViewState is a technique used by ASP.NET server controls to store and recover state. When a control renders itself to a page, it also encodes some data into a ViewState field. When a postback occurs, the server control will read in the ViewState field to recover it's state.
If the HtmlBox has undergone a lot of configuration, ViewState can become rather large. The following are techniques you can use to reduce/eliminate the size of ViewState.
Disable ViewState, perform configuration with each request
The simplest and most effective way to control ViewState size is simply to disable it. This is done by setting the EnableViewState property to false.
[C#] HtmlBox1.EnableViewState = false; [Visual Basic] HtmlBox1.EnableViewState = False
When EnableViewState is set to false, no ViewState information is stored on the page, completely eliminating overhead caused by ViewState. The drawback is that the control will not retain initial values with postbacks. As a result, the HtmlBox must be configured to your settings with each request (if you are using the default HtmlBox you do not need to reconfigure it). The following example demonstrates adding an Insert Table button and changing the background color to red. Note that this code is placed within the Page_Load event, so it runs with each request.
[C#] private void Page_Load(object sender, System.EventArgs e) { HtmlBox1.AddToolbarItem(ToolbarItemType.InsertTable); HtmlBox1.BackColor = Color.Red; } [Visual Basic] Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load HtmlBox.AddToolbarItem(ToolbarItemType.InsertTable) HtmlBox.BackColor = Color.Red End Sub
Send comments on this topic.
Documentation version 3.2.0.0.
© 2009 Dart Communications. All rights reserved.