动态 HTML 5 菜单不适用于回传

Dynamic HTML 5 menu does not work with postback

我正在生成 HTML 5 Menu 使用 ul 从后面的代码在母版页的页面加载中。它产生良好。但是出现的问题是在Post后面。菜单的动态内容在回发时消失。请让我知道如何在回发时重新呈现菜单。

其次我想知道为什么我用ASP.net Menu
就不会出现这个问题 也请让我知道动态菜单的任何其他最佳实践

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

这是我找到的解决我问题的唯一解决方案(在每次回发时再次呈现页面)

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