【问题标题】:How to access controls inside an asp.net wizard headertemplate?如何访问 asp.net 向导 headertemplate 中的控件?
【发布时间】:2014-01-20 10:38:47
【问题描述】:

当向导属性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>

【问题讨论】:

    标签: asp.net controls wizard


    【解决方案1】:

    从这个blog,解决方案是首先找到一个在运行时创建的控件HeaderContainer没有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;
    }
    

    【讨论】:

    • 如果没有定义 HeaderTemplate(或任何其他模板)怎么办?
    猜你喜欢
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多