我正在尝试使用自定义控件重新创建ASP.NET向导控件的功能。我无法使用向导控件,因为它重新加载页面并在table
中包装HTML。
控制标准: - 异步重新加载 - 能够从控件ID(.Next(),. Prev())
更改步骤目前它由两部分组成:
标记:
<asp:UpdatePanel id="upTest" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblbActiveStep" runat="server" Text="Label"></asp:Label>
<customControl:MultiStep ID="msExample" Visible="True" ActiveStepIndex="0" runat="server">
<customControl:Step runat="server" Name="Step 1">
<p>Step 1</p>
</customControl:Step>
<customControl:Step runat="server" Name="Step 2">
<p>Step 2</p>
</customControl:Step>
<customControl:Step runat="server" Name="Step 3">
<p>Step 3</p>
</customControl:Step>
</customControl:MultiStep>
<asp:Button ID="btnTest" OnClick="btnTest_OnClick" runat="server" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
我当前的代码适用于显示活动步骤,但在更新ActiveStepIndex时,它不会重新呈现。
MultiStep Control:
[ParseChildren(true, "Steps"), PersistChildren(false)]
public class MultiStep : CompositeControl
{
[PersistenceMode(PersistenceMode.InnerProperty)]
public StepList Steps { get; set; }
[PersistenceMode(PersistenceMode.InnerProperty)]
public int ActiveStepIndex { get; set; }
public MultiStep()
{
Steps = new StepList();
ActiveStepIndex = 0;
}
protected override void RenderChildren(HtmlTextWriter writer)
{
for (int i = 0; i < Steps.Count; i++)
{
Steps[i].Visible = (i == ActiveStepIndex);
if (Steps[i].Visible)
Steps[i].InstantiateIn(this);
}
base.RenderChildren(writer);
}
public void Next()
{
if (ActiveStepIndex < Steps.Count )
{
ActiveStepIndex++;
UpdateVisible(ActiveStepIndex);
}
}
private void UpdateVisible(int stepIndex)
{
foreach (Step step in Steps)
{
step.Visible = false;
}
Steps[ActiveStepIndex].Visible = true;
}
}
步骤子控制:
[ParseChildren(true, "Content"), PersistChildren(false)]
public class Step : CompositeControl
{
[PersistenceMode(PersistenceMode.InnerProperty)]
public string Name { get; set; }
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateContainer(typeof(MultiStep))]
[TemplateInstance(TemplateInstance.Single)]
public ITemplate Content { get; set; }
[PersistenceMode(PersistenceMode.InnerProperty)]
public Panel Panel { get; set; }
public Step()
{
}
public void InstantiateIn(Control container)
{
Content?.InstantiateIn(container);
}
}
StepList Collection
public class StepList : Collection<Step> { }
点击testing
按钮时,它会运行以下代码:
protected void testing_OnClick(object sender, EventArgs e)
{
msExample.Next();
}