2013-09-27 47 views
0

我需要您的幫助。我嘗試在我的Wizard控件中禁用linkbutton失敗。以編程方式創建的嚮導控制中禁用鏈接按鈕

我不能使用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是好的,而其餘的不是。

在此先感謝。

回答

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

這將使側邊欄可見,用高亮的鏈接到相應的步驟,無需被點擊。只有按鈕可用於導航。

+0

謝謝!有用。 – Karine

相關問題