title: asp.net button.onclientclick and button.text empty in jquery dialog
body: <p>I have a control that should prompt the user to choose either the session's customerId or the page's old ViewState customerId. If the value in the viewstate does not match the value in session a jQuery modal dialog will appear. The dialog has two buttons, one should display the ViewState value and the other should display the session value. The button with the ViewState value also has a OnClientClick property. I have tested this code with a simple test page that includes only a single button and my control. The simple test page worked. When I added this control to a an existing page I could get the dialog to show but button.text (assigned in the code behind) was empty and the function for OnClientClick would not fire.</p>
  
  <p>ascx</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
      function ShowCustomerChangedModalDialog() {
          var dlg = $("#CustomerChangedModal").dialog({
              title: 'Select Customer ID',
              resizable: false,
              modal: true
          });
          dlg.parent().appendTo(jQuery("form:first"));
      };
  
      function changeCustomer(customerId, baseUrl) {
          $.ajax({ url: "/General/Accounts/change.account?id=" + customerId + "&amp;admin=false", async: false });
          $("#CustomerChangedModal").dialog('close');
          return false;
      }
  
  &lt;/script&gt;
  
  &lt;div id="CustomerChangedModal" style="width: 440px; height: 250px; overflow: auto; display: none;"&gt;
      The session information has changed.
      Which account ID do you wish to use?
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;asp:Button ID="btnNewCustId" runat="server" OnClick="btnNewCustId_Click" /&gt;
      &lt;asp:Button ID="btnOldCustId" runat="server" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>code behind</p>
  
  <pre><code>public partial class CustomerChanged : System.Web.UI.UserControl
  {
      protected override void OnInit(EventArgs e)
      {
          base.OnInit(e);
          this.Page.PreLoad += Page_PreLoad;
      }
  
      void Page_PreLoad(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              ViewState.Add("CustID", Globals.CurrentCust.CustId);
          }
          if (IsPostBack)
          {
              Page.Validate();
              ValidateCustomerId();
          }
      }
  
      protected void ValidateCustomerId()
      {
          if (Convert.ToInt32(ViewState["CustID"]) != Globals.CurrentCust.CustId)
          {
              //button properties assignments
              btnOldCustId.Text += "Old AccountId\n" + ViewState["CustID"].ToString();
              btnNewCustId.Text += "New AccountId\n" + Globals.CurrentCust.CustId.ToString();
              btnOldCustId.OnClientClick = string.Format("return changeCustomer({0},'{1}');", ViewState["CustID"].ToString(), Globals.GeneralSiteUrl);
  
              CustomValidator err = new CustomValidator();
              err.IsValid = false;
              err.ErrorMessage = "The customer has changed.";
              Page.Validators.Add(err);
          }
      }
  
      protected void Page_Load(object sender, EventArgs e)
      {
  
          if (IsPostBack)
          {
              if (!Page.IsValid)
              {
                  ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "CustomerChangedModalDialog", "ShowCustomerChangedModalDialog();", true);
              }
          }
      }
  
      protected void btnNewCustId_Click(object sender, EventArgs e)
      {
          Response.Redirect(Request.RawUrl);
      }
  
  }
  </code></pre>
  
  <p>Any help would be appreciated.</p>