问题
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