Reputation: 12938
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
Upvotes: 2
Views: 9806
Reputation: 56
Little different version of what drs9222 had answered.
1. Declare a delegate
Public delegate void UserControlFormSubmit(object sender, EventArgs e);
2. Declare an event inside user control of type UserControlFormSubmit
Public event UserControlFormSubmit OnFormSubmit;
3. Set User control event as trigger for update panel like this
<asp:UpdatePanel ID="paymentFormUpdater" runat="server" UpdateMode=”Conditional” ChildrenAsTriggers=”true”>
<ContentTemplate>
<asp:PlaceHolder runat="server" ID="plcPaymentForm" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="paymentHeader1" EventName="OnFormSubmit" />
4. Raise the event OnFormSubmit when selectedindexchange event occurs for the radioButtonList. (Note that you need to set AutoPostBack=true for radioButtonList as mentioned by drs9222.
Upvotes: 4
Reputation: 4508
I see three quick and dirty ideas:
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
string value = ((RadioButtonList)sender).SelectedValue;
char? c = null;
if (!string.IsNullOrEmpty(value))
{
c = value[0];
}
RaiseBubbleEvent(this, new CommandEventArgs("SelectedIndexChanged", c));
}
protected override bool OnBubbleEvent(object source, EventArgs args)
{
if (args is CommandEventArgs)
{
CommandEventArgs cArgs = (CommandEventArgs)args;
if (cArgs.CommandName == "SelectedIndexChanged")
{
Control c = GetPaymentControl((char?)cArgs.CommandArgument);
// ...
updatePanel.Update();
return true;
}
}
return base.OnBubbleEvent(source, args);
}
Upvotes: 1