Domanda

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>
È stato utile?

Soluzione

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;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top