ASP.NET control lifecycle. Control property changes only available on next load
<p>I have built a pager control with various properties, for example <code>Start</code> to indicate the first record which should be rendered. This is embedded in another control which actually renders the list of records. The properties' getters and setters use ViewState to persist and retrieve the values.</p>

<p>The links in the pager are dynamically created during the page_load. On each link, the anchor.ServerClick delegate is wired up to a lambda that sets the Start property on the pager control.</p>

<p>When I debug the page, I can see that the Start property is indeed updated, but that the changed value is only available the next time I load the page, presumably persisted via the ViewState mechanism. </p>

<p>What this means in practice is that the embedding control doesn't see the updated values of these properties in time to render the correct list. How can I have the visitor's click update the pager properties before they get used rather than afterwards? </p>

<p>EDIT: adding some code</p>

<p>Called from the Page_Load of the main control, I have a loop that references the properties of the pager. This loop determines the items which will be displayed, and if the control properties were updated by this point, it would display the correct records, but that's not the case.</p>

<pre><code>for (int i = pager.Start - 1 ; 
          i &lt; queryResults.Count() &amp;&amp; i &lt;= (pager.Start + pager.PageSize); i++) {
</code></pre>

<p>In the pager control, also called from the Page_Load, there's code like this, that adds child controls and wires up the delegate. </p>

<pre><code>HtmlAnchor a = new HtmlAnchor();
a.HRef = "#";
a.InnerText = page.ToString();
newStartNumber = ((page - 1) * this.PageSize) + 1;
a.Attributes["data-start"] = newStartNumber.ToString();
a.ServerClick += (sender, e) =&gt; 
      { this.Start = int.Parse(((HtmlAnchor)sender).Attributes["data-start"]); };
li.Controls.Add(a);
ul.Controls.Add(li);
</code></pre>

<p>So when these anchors are clicked, the pager's Start property is updated, but it's too late. </p>
