How to change a View with a button on a Repeater?
<p>I have the following structure</p>

<pre><code>&lt;asp:UpdatePanel ID="MyUpdatePanel" runat="server"&gt;
    &lt;ContentTemplate&gt;
        &lt;asp:MultiView ID="MyViews" runat="server"&gt;
            &lt;asp:View ID="List" runat="server"&gt;
                &lt;asp:Repeater runat="server" ID="Repeater1"&gt;
                    &lt;ItemTemplate&gt;
                        &lt;asp:LinkButton ID="Button1" runat="server" Text="Button1" CommandName="View" /&gt;
                    &lt;/ItemTemplate&gt;
                &lt;/asp:Repeater&gt;
            &lt;/asp:View&gt;
            &lt;asp:View ID="Single" runat="server"&gt;
                &lt;asp:LinkButton ID="Button2" runat="server" Text="Button2" /&gt;
            &lt;/asp:View&gt;
        &lt;/asp:MultiView&gt;
    &lt;/ContentTemplate&gt;
&lt;/asp:UpdatePanel&gt;
</code></pre>

<p>On the code behind I get the repeater <code>ItemDataBound</code> event, get the control using <code>var button1 = e.Item.FindControl("Button1") as LinkButton;</code> then I assign a <code>CommandArgument</code> with the ID of the current element.</p>

<p>This is being executed immediately after the <code>CreateChildControls</code> method.</p>

<pre><code>Repeater1.ItemDataBound += (s, e) =&gt;
{
    if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
    {
        var Button1 = e.Item.FindControl("Button1") as LinkButton;
        Button1.CommandArgument = item.ID.ToString();
    }
};

Repeater1.ItemCommand += (s, e) =&gt;
{
    if (e.CommandName == "View")
    {
        var item = provider.Get(Convert.ToInt64(e.CommandArgument));
        BuildSingleView(item);
    }
};
</code></pre>

<p>This method just change the view...</p>

<pre><code>public void BuildSingleView(var item)
{
    MyViews.ActiveViewIndex = 1;
    /* Edit
       I've tried to call here
       Initialize(), EnsureChildControls(), CreateChildControls()
       but it was a useless try. I also tried to catch exceptions,
       but none happened.
     */
}
</code></pre>

<p>The problem is that the view doesn't change. When I click the LinkButton it executes the <code>CreateChildControls</code> and after it calls the event <code>ItemCommand</code>, the event calls the <code>BuildSingleView</code>, the <code>ActiveViewIndex</code> is changed but nothing happens on the page.</p>

<p>I don't understand why it doesn't change. Is it a problem with the order of events? What could I do to change the view when I click a LinkButton?</p>

<hr>

<p>Here is the full code-behind code (the Initialize method is the method that executes immediately after CreateChildControls) <a href="http://pastebin.com/2qwrKNxf" rel="nofollow">http://pastebin.com/2qwrKNxf</a></p>

<p>And here the full ascx file <a href="http://pastebin.com/P8RSbY9U" rel="nofollow">http://pastebin.com/P8RSbY9U</a></p>
