C# ASP.NET向导控件DropDownlist SelectedIndexChanged未启动

C# ASP.NET向导控件DropDownlist SelectedIndexChanged未启动,c#,asp.net,C#,Asp.net,当前我正在构建一个用于数据输入目的的向导控件,其中需要根据第一步的复选框列表中选择的项目动态构建步骤。我正在OnInit方法中动态构建向导及其控件,如下所示: WizardStep initiationStep = new WizardStep() { Title = "Add New Account/Service", ID = IniationStep" }; AddContentToInitiationStep(initiationStep); WizardStep drugAndAlc

当前我正在构建一个用于数据输入目的的向导控件,其中需要根据第一步的复选框列表中选择的项目动态构建步骤。我正在OnInit方法中动态构建向导及其控件,如下所示:

WizardStep initiationStep = new WizardStep() { Title = "Add New Account/Service", ID = IniationStep" };
AddContentToInitiationStep(initiationStep);

WizardStep drugAndAlcoholStep = new WizardStep() { Title = "Drug and Alcohol", ID = "DrugAndAlcStep" };
BuildDrugAndAlcoholWizardStep(drugAndAlcoholStep);

WizardStep omrtStep = new WizardStep() { Title = "OMRT", ID = "OMRTStep" };
BuildOMRTWizardStep(omrtStep);
这些步骤是预先加载的,我使用jQuery根据用户在复选框列表中选择的内容将它们隐藏在侧栏中。问题出在BuildDrugAndAlcoholWizardStep方法中。在该方法中,我使用自定义服务器控件来构建动态加载的中继器

private void BuildDrugAndAlcoholWizardStep(WizardStep step)
{
    AdvTable drugAndAlcoholTable = new AdvTable(0, 5);

    DataTable dt = ClientRegistrationServicesDB.ClientRegistrationServices_LoadByPolicyTemplateId(Config.GetDefaultDataStore(), policyTemplateId);

    var lblCollections = new Label() { Text = "Will this client use Consolidated Billing or will they pay the site directly?", CssClass = "label_l1" };
    AdvRadioButtonList radioBtnList = new AdvRadioButtonList() { ID = "BillType" };
    radioBtnList.Items.Add(new ListItem("Consolidated Billing", "ConsolidatedBilling"));
    radioBtnList.Items.Add(new ListItem("Pay Site Directly", "PaySiteDirectly"));

    AdvTabledRepeaterClientRegistrationDrugAndAlcohol mDrugAndAlc = new AdvTabledRepeaterClientRegistrationDrugAndAlcohol();

    drugAndAlcoholTable[0, 0].Controls.Add(lblCollections);
    drugAndAlcoholTable[1, 0].Controls.Add(radioBtnList);
    drugAndAlcoholTable[2, 0].Controls.Add(AdvQuickLiterals.BR);
    drugAndAlcoholTable[3, 0].Controls.Add(mDrugAndAlc);

    step.Controls.Add(drugAndAlcoholTable);
}
在实际中继器服务器控件中,我们有一个重写的CreateChildControls方法,该方法将实际控件添加到中继器:

protected override void CreateChildControls()
{
    base.CreateChildControls();

    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());

    this.Cells[0].Controls.Add(mPolicyTemplates);
    this.Cells[1].Controls.Add(DrugPrice);
    this.Cells[2].Controls.Add(AlcoholFee);
    this.Cells[3].Controls.Add(MemberSetupFee);
    this.Cells[4].Controls.Add(AnnualMaintenanceFee);
    this.Cells[5].Controls.Add(RandomRate);
    this.Cells[6].Controls.Add(TestPanel);
    this.Cells[7].Controls.Add(StartDate);

    mPolicyTemplates.ID = "PolicyTemplates";
    DrugPrice.ID = "DrugPrice";
    AlcoholFee.ID = "AlcoholFee";
    MemberSetupFee.ID = "MemberSetupFee";
    AnnualMaintenanceFee.ID = "AnnualMaintenanceFee";
    RandomRate.ID = "RandomRate";
    TestPanel.ID = "TestPanel";
    StartDate.ID = "StartDate";

    mPolicyTemplates.AutoPostBack = true;
    mPolicyTemplates.SelectedIndexChanged += PolicyTemplates_SelectedIndexChanged;
}
问题在于mPolicyTemplates下拉列表。中继器上有一个addnewrow链接,它导致为数据输入添加新行。该行是策略模板的下拉列表,当在下拉列表中选择策略模板时,它所选的行应该填充SelectedIndexChanged方法中数据库调用的数据,唯一的问题是它没有触发。对页面进行回发,服务器控制数据丢失以及应添加的新行。Init和Load方法在实际页面中被命中,但在服务器控件中没有触发任何事件

我已尝试在服务器控件的OnInit、OnLoad和OnDataBinding事件中放置AutoPostBack和SelectedIndexChanged初始值设定项,但该事件从未触发

我是否应该在生命周期的另一个方法中设置SelectedIndex changed事件?我是否需要在页面本身上执行某些操作,以便在选择下拉列表时,将正确的值加载到要插入的新行中


任何帮助都将不胜感激。

您是否尝试过将代码从受保护的override void CreateChildControls提升到中继器的init方法-我相信这可能会有所帮助。很好的建议,但即使将CreateChildControls代码移动到repeater的Init方法,它仍然不起作用;需要一个与之关联的ID-将控件生成保留在repeater init中,并为该项添加一个ID,然后进行尝试。也尝试了该操作,但仍然没有到达repeater中的事件处理程序。这可能与向导控件的生成方式有关吗?由于用户需要返回到任何步骤,并且数据仍然存在,因此我将在页面的OnInit方法中的每次回发中加载向导信息。这样做正确吗?mPolicyTemplates何时初始化?可能是添加事件处理程序,然后在某处重新实例化?mPolicyTemplates是否在任何时候存储在viewstate中?