title: Storing Viewstate in Database disables my asp:ImageButtons events
body: <p>I followed the guide <a href="http://www.componentworkshop.com/blog/2009/06/27/advanced-net-storing-viewstate-in-a-database" rel="nofollow">here to save my ViewState into the database</a>. I did some changes to it to fit my projects code design, but the essential parts are there. But when I implant this solution all my asp:ImageButtons events stops working, but regular asp:Buttons seems to work. Why doesn't the events from asp:ImageButtons work?</p>
  
  <p>Code:</p>
  
  <pre><code>public class DatabasePageStatePersister : PageStatePersister
  {        
      //This object handles the saving and loading from database
      CiroLightLibrary.BLL.ViewState myViewState;
  
      public DatabasePageStatePersister(Page p, string GUID): base(p)
      {
          myViewState = new CiroLightLibrary.BLL.ViewState();
          myViewState.GUID = GUID;
      }
  
      public override void Load()
      {
          myViewState.Load();
          this.ViewState = this.StateFormatter.Deserialize(myViewState.Value);
      }
  
      public override void Save()
      {
          myViewState.Value = this.StateFormatter.Serialize(this.ViewState);
          myViewState.Save();
      }
  }
  
  public class PageViewStateDatabaseStored : Page
  {
      private PageStatePersister _PageStatePersister;
  
      protected override System.Web.UI.PageStatePersister PageStatePersister
      {
          get
          {
              if (_PageStatePersister == null)
              {
                  CiroLightLibrary.BLL.ViewState myViewState = new ViewState();
  
                  if (Request["__DATABASE_VIEWSTATE"] != null)
                      myViewState.GUID = Request["__DATABASE_VIEWSTATE"].ToString();
                  else
                      myViewState.GUID = Guid.NewGuid().ToString();
  
                  _PageStatePersister = new DatabasePageStatePersister(this, myViewState.GUID);
  
                  Literal l = new Literal();
                  l.Text = "&lt;div&gt;&lt;input type=\"hidden\" name=\"__DATABASE_VIEWSTATE\" value=\"" + myViewState.GUID + "\" /&gt;&lt;/div&gt;";
                  this.Form.Controls.Add(l);
              }
  
              return _PageStatePersister;
          }
      }
  }
  </code></pre>
  
  <p>And heres a Test page:</p>
  
  <pre><code>public partial class test : PageViewStateDatabaseStored
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              imgButton1.CommandArgument = "1";
              btnButton1.CommandArgument = "1";
          }
      }
  
      protected void imgButton_OnCommand(object sender, CommandEventArgs e)
      {
          Response.Write(e.CommandArgument.ToString());
      }
  
      protected void imgButton_OnClick(object sender, EventArgs e)
      {
          Response.Write("Click");
      } 
  }
  </code></pre>
  
  <p>Asp.net Page</p>
  
  <pre><code>    &lt;form runat="server"&gt;
          &lt;asp:ImageButton ID="imgButton1" runat="server" OnCommand="imgButton_OnCommand" /&gt;
          &lt;asp:ImageButton ID="imgButton2" runat="server" OnClick="imgButton_OnClick" /&gt;
  
          &lt;asp:Button ID="btnButton1" runat="server" OnCommand="imgButton_OnCommand" /&gt;
          &lt;asp:Button ID="btnButton2" runat="server" OnClick="imgButton_OnClick" /&gt; 
      &lt;/form&gt;
  </code></pre>