Allocating and deallocating event on a button
<p>I am busy having a problem with allocating a new event to an existing button that was created in the designer.</p>

<p>Now here is the button that was created prior to runtime which is inside the modalpopupexteder5 -</p>

<pre><code>&lt;asp:Button runat="server" ID="btnClose" Text="Close" OnClick="btnClose_Click" /&gt;
</code></pre>

<p>Here is the codebehind - </p>

<pre><code>    protected void btnAddAccount_Click(object sender, EventArgs e)
    {
        btnClose.Click -= new EventHandler(btnClose_Click);
        btnClose.Click += new EventHandler(btnCancel_Click);
        ModalPopupExtender5.Show();            
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        ModalPopupExtender11.Hide();
    }

    protected void btnClose_Click(object sender, EventArgs e)
    {
        ModalPopupExtender5.Hide();

    }
</code></pre>

<p>So the button in the beginning has the event btnClose_Click hooked up to it. But I want to change it to the btnCancel_Click</p>

<p>But it wont execute the btnCancel_Click. It executes the original btnClose_Click</p>

<p>Any Ideas what could of caused this?</p>

<p>Does this relate to the page life cycle?</p>

<p><strong>--EDIT--</strong>
I should let you know that the btnAddAccount_Click does get executed.</p>

<p>Basically I don't to create the same modalpopupextender, I want to use the existing one but depending on user selection will determine which eventhandler should be called and in this case the btnAccount_Click has selected the btnCancel_Click to be assigned to the button.</p>
