禁用以编程方式创建的Wizard Control中的链接按钮

时间:2013-09-27 10:28:15

标签: asp.net code-behind wizard sidebar linkbutton

我需要你的帮助。我尝试在Wizard控件中禁用链接按钮失败。

我无法使用javascript,我必须使用userControl。

我不想要这个功能,因为如果我在步骤4中并且单击步骤1的链接,则我的数据不会持久存在(每个wizardStep包含不同的UserControl)。如果您认为可以解决此问题,我不需要解决链接按钮问题。

我认为我的问题是由于向导,因为我试试这个: Disable linkbutton programmatically 它仍然不起作用:(

linkbutton.commandName = null似乎有效。我可以点击但它不会改变当前的wizardStep。

这是我的代码:

public class EditOrNew : UserControl
{
    Wizard w = new Wizard();
    WizardStep ws1 = new WizardStep();
    WizardStep ws2 = new WizardStep();
    WizardStep ws3 = new WizardStep();
    WizardStep ws4 = new WizardStep();

    protected override void OnInit(EventArgs e)
    {
        w.ID = "w";                 
        ws1.ID = "ws1";
        ws2.ID = "ws2";
        ws3.ID = "ws3";
        ws4.ID = "ws4";
        ws1.Title = "Select a client";            
        ws1.StepType = WizardStepType.Start;
        ws2.Title = "Select a project";
        ws3.Title = "Select a bot type";
        ws4.Title = "Configure the new task";
        ws4.StepType = WizardStepType.Finish;
    }

    protected override void CreateChildControls()
    {
        this.Controls.Add(w);
        // Allow access to buttonlink in the wizard
        Control ctrl = w.FindControl("SideBarContainer");
        DataList dl = (DataList)ctrl.FindControl("SideBarList");
        foreach (DataListItem item in dl.Items)
        {
            LinkButton b = (LinkButton)item.FindControl("SideBarButton"); 
            b.CommandName = null;  
            // NOT WORK      
            //b.Attributes.Add("disabled", "disabled"); 
            //b.ForeColor = System.Drawing.Color.Pink;                               
            //b.Attributes.CssStyle[HtmlTextWriterStyle.Cursor] = "default";
            //b.Enabled = false;
            //b.OnClientClick = null;
            //b.Attributes.Remove("href");
            //b.Attributes.CssStyle[HtmlTextWriterStyle.Color] = "gray";                
        }
     }

我尝试将允许访问代码放到不同的位置。

我不明白为什么commandName没有问题而其余部分没有。

提前致谢。

1 个答案:

答案 0 :(得分:0)

向导步骤绑定到DataList dl中,因此您可以向dl添加处理程序:

protected override void OnInit(EventArgs e)
{
    w.ID = "w";                 
    ws1.ID = "ws1";
    ws2.ID = "ws2";
    ws3.ID = "ws3";
    ws4.ID = "ws4";
    ws1.Title = "Select a client";            
    ws1.StepType = WizardStepType.Start;
    ws2.Title = "Select a project";
    ws3.Title = "Select a bot type";
    ws4.Title = "Configure the new task";
    ws4.StepType = WizardStepType.Finish;

    DataList dl= (DataList)w.FindControl("SideBarContainer").FindControl("SideBarList");
    dl.ItemDataBound += w_ItemDataBound;
}

void w_ItemDataBound(object sender, DataListItemEventArgs e)
{
    LinkButton lb = e.Item.FindControl("SideBarButton") as LinkButton;
    if (lb != null)
    {
        lb.Enabled = false;
    }
}

这将使侧边栏可见,链接突出显示到相应的步骤而不是可点击的。只有按钮可用于导航。