title: Attributes.add, ScriptManager.RegisterStartupScript, ScriptManager.RegisterClientScriptBlock not working
body: <p>I have a button on a webform, inside an update panel that is inside an Ajax Toolkit tabcontainer, that saves data in the textboxes to the database. I have five <code>if</code> statements that validate date ranges on the page and put up an alert if the ranges are invalid using (for example):</p>
  
  <pre><code>If &lt;condition&gt; Then
      ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "alertMessage", "alert('Actual end date cannot be earlier than Sign date.');", True)
      updateFlag = False
  End If
  </code></pre>
  
  <p>This code works fine. A flag is set for updating the data. The problem is if the code falls through the <code>if</code> into the update section: the <code>alert</code> I put there saying "Data saved" doesn't pop up after the updates are done. I've used each of the following:</p>
  
  <pre><code>ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "alertMessage", "alert('Job saved.');", True)
  ScriptManager.RegisterStartupScript(Me, Me.GetType(), "alertMessage", "alert('Job saved.');", True)
  Me.btnSave.Attributes.Add("onclick", "alert('Job saved.');")
  ClientScript.RegisterStartupScript() 'don't have the rest of this line
  </code></pre>
  
  <p>None of them have worked. The data is saved as it should be; it's as if the code jumps over the <code>alert</code> line. I would be very grateful if anyone could help me.</p>
  
  <p>Edit: clarifying that I put <code>Me.btnSave.Attributes.Add("onclick", "alert('Job saved.');")</code> in the Page_Load as well as after the update statements, but that one fires before the data is actually saved, so that error messages are received after the data is "saved". Wrong order, can't use it.</p>
  
  <p>Edit 2: Posting more code. Code behind:</p>
  
  <pre><code>Protected Sub SaveAll()
      If &lt;condition&gt; Then
          ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "alertMessage", "alert('Actual end date cannot be earlier than Sign date.');", True)
          updateFlag = False
      End If
      ...
      If updateFlag Then
          'add values to SqlDataAdapter
          ...
          con.Open()
          da.SelectCommand.ExecuteNonQuery()
          con.Close()
          da.Dispose()
          ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "alertMessage", "alert('Job saved.');", True)
          'ScriptManager.RegisterStartupScript(Me, Me.GetType(), "alertMessage", "alert('Job saved.');", True)
          'Me.btnSave.Attributes.Add("onclick", "alert('Job saved.');")
          Response.Redirect("Edit.aspx?ID=" &amp; txtID.Text)
      End If
  End Sub
  </code></pre>
  
  <p>aspx:</p>
  
  <pre><code>&lt;ajaxToolkit:TabContainer ID="TabContainer1" 
      runat="server" TabStripPlacement="Top"&gt;
  &lt;ajaxToolkit:TabPanel runat="server" ID="JobPanel" HeaderText="Job Info"&gt;
  &lt;ContentTemplate&gt;
  &lt;asp:UpdatePanel ID="updatePanel1" runat="server"&gt;
  &lt;ContentTemplate&gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;asp:Button ID="btnSave" OnClick="SaveAll" 
                  runat="server" Text="Save" /&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  &lt;/ContentTemplate&gt;
  &lt;/ajaxToolkit:TabPanel&gt;
  &lt;/ajaxToolkit:TabContainer&gt;
  </code></pre>
  
  <p>Please let me know if you need more code.</p>