Values of ASP.NET Controls are cleared on postback


I came accros this issues when I was trying to export a gridview that I made to excel. When I pressed my “Export To Excel” button on my custom ASPX page the gridview turned to null.

To be able to re-use data in an ASP.NET control after doing a postback, the EnableViewState property of the control and the page must be set to true.

When you create a new ASP.NET page this is the case by default. Except when you deploy this page to MS CRM 4.0 it is likely your code will not work as you excpected because MS CRM 4.0 disables the viewstate of all it’s pages in it’s web.config file.

To avoid this issue be sure to enable the viewstate in your custom page.

Example:

< %@ Page Language="C#" AutoEventWireup="true" CodeFile="MyPage.aspx.cs"    Inherits="MyPage" EnableViewState="true % >
Advertisements
Tagged with: ,
Posted in CRM 4

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: