如何访问asp.net向导headertemplate中的控件?

时间:2014-01-02 21:22:39

标签: asp.net controls wizard

当向导属性DisplaySideBarFalse时,此代码具有向导步骤标题,但不起作用,标签lbl将为null

protected void Wizard1_ActiveStepChanged(object sender, EventArgs e)
{
// Grab a reference to the label control
Label lbl = (Label)Wizard1.FindControl("lblStepTitle");
lbl.Text = Wizard1.ActiveStep.Title;
}

HTML(省略了向导步骤):

<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" DisplaySideBar="False"
OnActiveStepChanged="Wizard1_ActiveStepChanged"
            OnNextButtonClick="Wizard1_NextButtonClick" 
            OnFinishButtonClick="Wizard1_FinishButtonClick">
            <HeaderStyle HorizontalAlign="Center" Font-Bold="True" />
            <HeaderTemplate>
                Edit User Wizard
                <br />
                <br />
                <asp:Label ID="lblStepTitle" runat="server" Text="Step Title"></asp:Label>
            </HeaderTemplate>
</asp:Wizard>

1 个答案:

答案 0 :(得分:0)

从这个blog,解决方案是首先找到在运行时创建的控件HeaderContainer no MSDN page

记录的位置
protected void Wizard1_ActiveStepChanged(object sender, EventArgs e)
{
    // Grab a reference to the label control
    Label lbl = (Label)Wizard1.FindControl("HeaderContainer").FindControl("lblStepTitle");
    lbl.Text = Wizard1.ActiveStep.Title;
}