How to access controls inside an asp.net wizard headertemplate?

不打扰是莪最后的温柔 提交于 2019-12-11 14:54:52

问题


This code to workaround having a wizard step title when wizard property DisplaySideBar is False, will not work, the label lbl will be 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;
}

The HTML (ommited the wizard steps):

<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:


From this blog, the solution is to first find a control created at runtime HeaderContainer no where documented by the 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;
}


来源:https://stackoverflow.com/questions/20892141/how-to-access-controls-inside-an-asp-net-wizard-headertemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!