Pergunta

I need your help. I try unsuccessfully to disable linkbutton in my Wizard control.

I cannot use javascript and I must use a userControl.

I do not want this functionnality because if I am in step 4 and I click on link for step 1, my data does not persist (each wizardStep contains a different UserControl). If you think you can resolve this problem, I do not need to resolve linkbutton problem.

I think my problem is due to the wizard because I try this : Disable linkbutton programmatically and it still not works :(

linkbutton.commandName = null seems to work. I can click but it does not change the current wizardStep.

This is my code :

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

I try to put the allow access code to different place.

I do not understand why commandName is OK while the rest is not.

Thanks in advance.

Foi útil?

Solução

The wizard steps are binded into the DataList dl, so you can add an handler to 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;
    }
}

This will leave the sidebar visible, with links highlighted to the corresponding step without being clickable. Only the buttons will be available to navigate then.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top