title: ASP.net UpdatePanel - Works first time then fails
body: <p>I have a simple update panel that contains an ASP DataList.  It shows a list of documents and their approval status.  Here is some sample markup</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="upDocuments" runat="server" UpdateMode="Always"&gt;
      &lt;ContentTemplate&gt;
          &lt;asp:DataList ID="dlDocuments" runat="server" RepeatLayout="Table"&gt;
              &lt;HeaderTemplate&gt;
                  &lt;table cellpadding="0" cellspacing="0" style="width:100%;"&gt;
                      &lt;thead&gt;
                          &lt;th&gt;&lt;span style="font-size:110%;"&gt;User Documents&lt;/span&gt;&lt;/th&gt;
                          &lt;th&gt;&lt;/th&gt;
                          &lt;th&gt;&lt;/th&gt;
                          &lt;th&gt;&lt;/th&gt;
                      &lt;/thead&gt;
              &lt;/HeaderTemplate&gt;
              &lt;ItemTemplate&gt;
                      &lt;tr&gt;
                          &lt;td&gt;
                              &lt;asp:HyperLink ID="lnkDocName" runat="server" /&gt;&lt;/td&gt;
                          &lt;td&gt;
                              &lt;asp:Label ID="lblDocType" runat="server" /&gt;&lt;/td&gt;
                          &lt;td&gt;
                              &lt;asp:Label ID="lblApproved" runat="server" /&gt;&lt;/td&gt;
                          &lt;td&gt;
                              &lt;asp:LinkButton ID="btnApprove" runat="server" Visible="false" Text="Approve" /&gt;&amp;nbsp;&amp;nbsp;
                              &lt;asp:Label ID="lblApprovedBy" runat="server" /&gt;&lt;/td&gt;
                      &lt;/tr&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;/table&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:DataList&gt;
      &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>In my code-behind, I have a routine called from Page_Load to get the data and bind it to the DataList. Here are the relevant lines.</p>
  
  <pre><code>// Load the documents - loaded to docList (List&lt;Document&gt;)
  dlDocuments.DataSource = docList;
  dlDocuments.DataBind();
  </code></pre>
  
  <p>All is great so far. Then, during the DataList's item bound handler, I bind the btnApprove control to a handler to load the document and approve it.</p>
  
  <pre><code>if (!doc.Approved)
  {
      LinkButton btnApprove = (LinkButton)e.Item.FindControl("btnApprove");
      btnApprove.Click += new EventHandler(btnApprove_Click);
      btnApprove.Attributes.Add("docKey", doc.docKey);
      btnApprove.Visible = true;
  }
  </code></pre>
  
  <p>Then,</p>
  
  <pre><code>protected void btnApprove_Click(object sender, EventArgs e)
  {
      LinkButton btnApprove = (LinkButton)sender;
      int docKey = Int32.Parse(btnApprove.Attributes["docKey"]);
      Document doc = // Load document
      doc.Approved = true;
      doc.ApprovedBy = Page.User.Identity.Name;
      doc.ApprovedDate = DateTime.Now;
  
      // Save doc back to DB
  
      LoadUserDocuments();
  }
  </code></pre>
  
  <p>Again, all is great. I load the page, see the documents and their status and the links. My test case goes like this:</p>
  
  <ol>
  <li>Load the page</li>
  <li>Click "Approve" for the first document.</li>
  <li>Verify it is approved.</li>
  <li>Click "Approve" for the second document.</li>
  <li>Verify it is approved.</li>
  </ol>
  
  <p>My test fails on step 5. I've debugged and the click handler is called, the DataList is re-bound to the results and the document is saved back to the database as approved. However, the page never refreshes to show the updated status of the second document. Does anyone know what step I'm missing on the post back that causes subsequent post backs to fail?</p>