0
votes

I have an aspx.

<div id="headerRegion" class="borderDiv">
    <xy:paymentHeader id="paymentHeader1" runat="server" />
</div>
<div id="paymentRegion" class="borderDiv">
    <asp:UpdatePanel ID="paymentFormUpdater" runat="server">
        <ContentTemplate>
            <asp:PlaceHolder runat="server" ID="plcPaymentForm" />
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

on page init, the placeHolder loads an ascx.

private Control GetPaymentControl(char? coverageBenefitPeriod)
{
    Control paymentCtl = null;
    switch (coverageBenefitPeriod)
    {
        case 'L':
            paymentCtl = this.LoadControl("~/Controls/Lumpform.ascx");
            break;
        case 'W':
            paymentCtl = this.LoadControl("~/Controls/Periodicform.ascx");
            break;
        default:
            paymentCtl = this.LoadControl("~/Controls/Lumpform.ascx");
            break;
    }
    return paymentCtl;
}
plcPaymentForm.Controls.Add(control);

There's a radioButton List on paymentHeader1 control. When I toggle that radio button would like to elegantly swap between Periodicform.ascx and Lumpform.ascx in the placeholder "plcPaymentForm". How do I do this correctly? I am trying not to load both controls and toggle their visibility. If you have any ideas how to do this properly with minimal page interuption please point me in the right direction.

Thanks, ~ck in San Diego

2

2 Answers

0
votes

You could do something like:

protected void rbl_Changed(object sender, EventArgs e)
{
    if(rbl.SelectedItem.Text == "Periodicform")
        Page.FindControl("plcPaymentForm") = LoadControl("Periodicform.ascx");
    else if(rbl.SelectedItem.Text == "Lumpform")
        Page.FindControl("plcPaymentForm") = LoadControl("Lumpform.ascs");
}
0
votes

On Init you need to load whichever one is currently shown, or viewstate will fail to load. Then on the event handler for the radio button changed event (assuming you have auto postback on and the necessary AJAX triggers sorted), Load the new paymentCtl as you have done, but clear the plcPaymentForm.Controls collection, before you add it in.

If you need to you can call Update() (or is it Refresh()) on the UpdatePanel to force a refresh of its content from the controls outside of it, or set it to refresh on every postback, depending on what controls and what postbacks you are doing.