Spread for ASP.NET 11 Product Documentation
Understanding Postback and Page Load Events
Spread for ASP.NET 11 Product Documentation > Developer's Guide > Managing Data in the Component > Server-Side Scripting > Understanding Postback and Page Load Events

When you run an ASP.NET application, the FpSpread component on the server outputs its data and settings in HTML, which is sent to the client along with scripting if the EnableClientScript property is set to true and the client’s browser can handle or is set to allow scripting.

Code you have added to the PageLoad event in your application occurs at the time the HTML page is sent from the server, and every time the page is sent from the server. Therefore, it is important to understand that every action that you provide or that users perform that initiates a postback to the server loads a new page into the browser. Any code you have in the PageLoad event is re-executed at the time the new page is sent.

For example, if you set data in a cell in the PageLoad event, such as setting cell A1 to the value 100, then the user changes the value in the cell, then clicks a button, the page posts back to the server, and the PageLoad event resets the value of the cell to 100. The user’s data is lost.

To deal with this chain of events in the page loads, you should add code to the PageLoad event that checks if the page is a postback or the initial load of the page.

Use a single line in the PageLoad event.

Example

Use the following code in the PageLoad event to prevent inadvertent changes to pages due to post backs:

C#
Copy Code
if (this.IsPostBack) return;
VB
Copy Code
If (IsPostBack) Then
  Return
End If