我有一个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>
在init页面上,placeHolder加载了一个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(对照);
paymentHeader1控件上有一个radioButton List。当我切换那个单选按钮想在占位符“plcPaymentForm”中优雅地在Periodicform.ascx和Lumpform.ascx之间交换。我该怎么做呢?我试图不加载两个控件并切换其可见性。如果你有任何想法如何正确地做到这一点,最小的页面中断,请指出我正确的方向。
谢谢, 〜在圣地亚哥
答案 0 :(得分:4)
drs9222回答的版本差别不大。
1.宣布代表
Public delegate void UserControlFormSubmit(object sender, EventArgs e);
2.在UserControlFormSubmit类型的用户控件中声明一个事件
Public event UserControlFormSubmit OnFormSubmit;
3.将用户控件事件设置为更新面板的触发器,如下所示
<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.当radioButtonList发生selectedindexchange事件时,引发事件OnFormSubmit。 (注意,您需要为drs9222提到的radioButtonList设置AutoPostBack = true。
答案 1 :(得分:1)
我看到了三个快速而肮脏的想法:
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);
}