title: Why aren't the ASP.NET User Control properties updated within the control?
body: <h2>Overview</h2>
  
  <p>I have a ASCX user control that I am trying to use for my web application.</p>
  
  <p>The control has multiple properties that need to be set in order for the control to work properly.</p>
  
  <p>The control is used in a GridView. Each instance of the control needs data from the row it is on.</p>
  
  <h2>What I Have Tried</h2>
  
  <p>I have tried setting the property values using the attributes and the <code>Eval</code> method to assign the values. For example:</p>
  
  <p><strong><em>Page Code:</em></strong></p>
  
  <pre><code>&lt;cm:TestManagerEditor runat="server" id="TestManagerEditor" FilePath='&lt;%# System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "Some\\Path\\In\\The\\WebApp\\" + AccountYearPeriodOptionsGroupRandomTestManager.SelectedAccountValue + "\\" %&gt;' /&gt;
  </code></pre>
  
  <p>I have also tried setting the values on the <code>RowDataBound</code> event. For example:</p>
  
  <p><strong><em>Page Code:</em></strong></p>
  
  <pre><code>private string PathToUserFiles = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "Some\\Path\\In\\The\\WebApp\\";
  
  protected void GridViewData_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      // this is the customized path to files for the selected account.
      string UserFilePath = PathToUserFiles + AccountYearPeriodOptionsGroupRandomTestManager.SelectedAccountValue + "\\";
  
      // set modal dialog properties and add the scripting to open those dialogs.
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
          Controls_Modals_TestManagerEditor EditorModal = e.Row.FindControl("TestManagerEditor") as Controls_Modals_TestManagerEditor;
  
          EditorModal.FilePath = UserFilePath;
      }
  }
  </code></pre>
  
  <h2>The Problem</h2>
  
  <p>When I access the properties that I set using either of the methods above from the <em>page</em> the control is on, the values return correctly. However, if I am attempting to access the value of the property from within the codebehind of the control, it returns the default value of the property (usually <code>NULL</code> or <code>string.Empty</code>) and not the value that was set.</p>
  
  <p>For example, the <code>FilePath</code> property used above is declared just like any other:</p>
  
  <p><strong><em>UserControl Code:</em></strong></p>
  
  <pre><code>/// &lt;summary&gt;
  /// The path to the location of the uploaded files.
  /// &lt;/summary&gt;
  private string _FilePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "Some\\Path\\In\\The\\WebApp\\";
  
  /// &lt;summary&gt;
  /// Gets or sets the path to the location of uploaded files.
  /// &lt;/summary&gt;
  public string FilePath
  {
      get
      {
          return _FilePath;
      }
      set
      {
          _FilePath = value;
      }
  }
  </code></pre>
  
  <p>But when the user clicks a button on the control to perform some operation, the value of <code>FilePath</code>, when accessed in the UserControl's code is</p>
  
  <pre><code>System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "Some\\Path\\In\\The\\WebApp\\"
  </code></pre>
  
  <p>and not the expected</p>
  
  <pre><code>System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "Some\\Path\\In\\The\\WebApp\\" + AccountYearPeriodOptionsGroupRandomTestManager.SelectedAccountValue
  </code></pre>
  
  <p>(essentially missing the <code>AccountYearPeriodOptionsGroupRandomTestManager.SelectedAccountValue</code> from the string).</p>
  
  <p>The odd thing is that the properties will actually perform the <code>set</code> operation. One of them for sure will perform the operation but then promptly loses it's value. The <code>ModalTitle</code> property will set the UX correctly, but accessing the value of the property afterwards fails to return what is displayed on the screen.</p>
  
  <p>For example, the following set accessor will correctly set the <code>TestManagerEditor_label</code> values on the screen, but fails to set the value of <code>_ModalTitle</code>:</p>
  
  <p><strong><em>UserControl Code:</em></strong></p>
  
  <pre><code>/// &lt;summary&gt;
  /// The text to display in the title of the Modal Dialog Box.
  /// &lt;/summary&gt;
  private string _ModalTitle = "Test Manager";
  
  /// &lt;summary&gt;
  /// Gets or sets the text to display in the title of the Modal Dialog Box.
  /// &lt;/summary&gt;
  public string ModalTitle
  {
      get
      {
          return _ModalTitle;
      }
      set
      {
          _ModalTitle = value;
          TestManagerEditor_label.InnerText = value + " ";
          TestManagerEditor_label.InnerHtml = TestManagerEditor_label.InnerHtml + "&lt;span class=\"fa fa-pencil\"&gt;&lt;/span&gt;";
      }
  }
  </code></pre>
  
  <p>Does anyone know what's going on here and why my control isn't able to access or save the value of the properties that are set by its parent page?</p>