我正在使用母版页面加载中的代码后面的 ul 生成 HTML 5 菜单。它生成了很好的。但问题发生在Post back。菜单的动态内容在回发时消失。请让我知道如何在回发时重新呈现菜单。
其次我想知道如果我使用 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 :(得分: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);
}
}