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.
< %@ Page Language="C#" AutoEventWireup="true" CodeFile="MyPage.aspx.cs" Inherits="MyPage" EnableViewState="true % >