2016-12-13 75 views
0

工作,我產生HTML 5菜單在母版頁的頁面加載使用UL從後面的代碼。它生成的很好。但問題發生在Post回來。回髮菜單的動態內容消失。請讓我知道如何重新在回髮菜單。動態HTML 5菜單不回發

第二,我想知道爲什麼,如果我使用ASP.net菜單
也請讓我知道動態菜單

<ul runat="server" id ="Menu"></ul> 

代碼後面的任何其他最佳實踐不會出現此問題:

public void Page_Load(object sender, EventArgs e) 
{ 
    if (IsPostBack) 
    { 
     return; 
    } 
    try 
    { 
     if (Session["user"] == null || Request.QueryString["applicationID"] == null) 
     { 
      throw new Exception("Invalid Session. Please login again!"); 
     } 
     Application1 appRow = bal.GetApplication(ApplicationID)[0]; 
     PanelQuickJump.Visible = Boolean.Parse(Session["IsAdmin"].ToString()) && (TaskID == 9 || TaskID == 25 || TaskID == 33 || TaskID == 55) && (appRow.ApplicationClosed != true);    
     ImageButtonSearch.Attributes.Add("onclick", "window.open ('SearchPop.aspx',null,'scrollbars=yes, status= no, resizable = yes, toolbar=no,location=no,height = 700, width = 1200, left = 200, top= 200, screenx=10,screeny=600,menubar=no');"); 

     /* get task */ 
     activeTask = bal.GetActiveTask(ApplicationID, Employee.EmployeeID)[0]; 
     //applicant = employeeAdapter.GetApplicant(ApplicationID)[0]; 
     LabelTaskName.Text = activeTask.Task; 
     /* get menu items */ 
     List<TaskForm1> taskForms = bal.GetTaskFormByTask(activeTask.TaskID, activeTask.SubTaskID); 
      foreach (TaskForm1 row in taskForms) 
     { 
      li = new HtmlGenericControl("li"); 
      anchor = new HtmlGenericControl("a"); 
      string itemURL = row.Page + "?applicationID=" + ApplicationID;    
      if (row.Checkable == true) 
      { 
       string reqMenuItem = "<span style=\"color: #669900; font-weight: bold\">" + row.Title + "</span>"; 
       anchor.InnerText = reqMenuItem; 
       anchor.Attributes.Add("href", itemURL);         
      } 
      else 
      { 
       anchor.Attributes.Add("href", itemURL); 
       anchor.InnerText = row.Title ; 
      } 

      if (row.Page == CurrentPageName) 
      { 
       anchor.InnerText = row.Title ; 
      } 
      li.Controls.Add(anchor); 
      Menu.Controls.Add(li); 
} 
} 

回答

0

這是我發現的唯一解決方案(再次呈現在頁面上每次回發)解決我的問題

public void Page_Load(object sender, EventArgs e) 
{ 
// if (IsPostBack) 
// { 
// return; 
// } 

    try {   
if (Session["user"] == null || Request.QueryString["applicationID"] == null) 
    { 
     throw new Exception("Invalid Session. Please login again!"); 
    } 
    Application1 appRow = bal.GetApplication(ApplicationID)[0]; 
    PanelQuickJump.Visible = Boolean.Parse(Session["IsAdmin"].ToString()) && (TaskID == 9 || TaskID == 25 || TaskID == 33 || TaskID == 55) && (appRow.ApplicationClosed != true);    
    ImageButtonSearch.Attributes.Add("onclick", "window.open ('SearchPop.aspx',null,'scrollbars=yes, status= no, resizable = yes, toolbar=no,location=no,height = 700, width = 1200, left = 200, top= 200, screenx=10,screeny=600,menubar=no');"); 

    /* get task */ 
    activeTask = bal.GetActiveTask(ApplicationID, Employee.EmployeeID)[0]; 
    //applicant = employeeAdapter.GetApplicant(ApplicationID)[0]; 
    LabelTaskName.Text = activeTask.Task; 
    /* get menu items */ 
    List<TaskForm1> taskForms = bal.GetTaskFormByTask(activeTask.TaskID, activeTask.SubTaskID); 
     foreach (TaskForm1 row in taskForms) 
    { 
     li = new HtmlGenericControl("li"); 
     anchor = new HtmlGenericControl("a"); 
     string itemURL = row.Page + "?applicationID=" + ApplicationID;    
     if (row.Checkable == true) 
     { 
      string reqMenuItem = "<span style=\"color: #669900; font-weight: bold\">" + row.Title + "</span>"; 
      anchor.InnerText = reqMenuItem; 
      anchor.Attributes.Add("href", itemURL);         
     } 
     else 
     { 
      anchor.Attributes.Add("href", itemURL); 
      anchor.InnerText = row.Title ; 
     } 

     if (row.Page == CurrentPageName) 
     { 
      anchor.InnerText = row.Title ; 
     } 
     li.Controls.Add(anchor); 
     Menu.Controls.Add(li); 
} 
}