如何访问一个asp.net向导HeaderTemplate中内部控制? [英] How to access controls inside an asp.net wizard headertemplate?

查看:184
本文介绍了如何访问一个asp.net向导HeaderTemplate中内部控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这code要解决有一个向导,一步冠军时,向导财产 DisplaySideBar ,不会工作中,标签 LBL

 保护无效Wizard1_ActiveStepChanged(对象发件人,EventArgs的发送)
{
//抢在标签控件的引用
标签LBL =(标签)Wizard1.FindControl(lblStepTitle);
lbl.Text = Wizard1.ActiveStep.Title;
}

中的HTML(ommited向导步骤):

 < ASP:精灵ID =Wizard1=服务器ActiveStepIndex =0DisplaySideBar =FALSE
OnActiveStepChanged =Wizard1_ActiveStepChanged
            OnNextButtonClick =Wizard1_NextButtonClick
            OnFinishButtonClick =Wizard1_FinishButtonClick>
            < HeaderStyle Horizo​​ntalAlign =中心字体粗体=真/>
            <&HeaderTemplate中GT;
                编辑用户向导
                < BR />
                < BR />
                < ASP:标签ID =lblStepTitle=服务器文本=步骤标题>< / ASP:标签>
            < / HeaderTemplate中>
< / ASP:精灵>


解决方案

此的博客,解决的办法是先找到 HeaderContainer 在运行时创建一个控制任何地方通过的 MSDN页面

 保护无效Wizard1_ActiveStepChanged(对象发件人,EventArgs的发送)
{
    //抢在标签控件的引用
    标签LBL =(标签)Wizard1.FindControl(HeaderContainer)的FindControl(lblStepTitle);
    lbl.Text = Wizard1.ActiveStep.Title;
}

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>

解决方案

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;
}

这篇关于如何访问一个asp.net向导HeaderTemplate中内部控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆