会话过期时,动态HTMLControl的事件不会触发

时间:2013-09-16 08:34:54

标签: c# asp.net

我根据存储在Session中的List在我的页面上创建了3个动态链接按钮。我的页面加载后,我等到我知道会话已经过期并尝试点击按钮然后我注意到事件没有触发,按钮就消失了。如果会话尚未过期,按钮工作正常。

这是按钮生成和再生:

void GetHelpdeskSystems()
{
    HelpdeskSysEOList hdList = new HelpdeskSysEOList();
    hdList.Load();
    List<HelpdeskSysEO> active = hdList.Where(h => h.IsActive).ToList();
    int x = 0;
    foreach (HelpdeskSysEO hd in active)
    {
        LinkButton lb = new LinkButton();
        lb.ID = "lnkhd_" + x;
        lb.CommandArgument = hd.ID.ToString();
        lb.CommandName = "btnHelpdesk";
        lb.Attributes.Add("class", "lnkhelpdesk roundcor bluebtn");
        lb.Command += btnHeldesk_Command;
        HtmlGenericControl img = new HtmlGenericControl("img");
        if (!string.IsNullOrEmpty(hd.ImageIcon))
            img.Attributes.Add("src", "images/icons/" + hd.ImageIcon);
        else
            img.Attributes.Add("src", "images/icons/default.png");
        HtmlGenericControl span = new HtmlGenericControl("span");
        span.InnerText = hd.HelpdeskName.Replace("Helpdesk", "").Replace("HELPDESK", "").Replace("helpdesk", "");
        lb.Controls.Add(img);
        lb.Controls.Add(span);
        divHelpdeskSystemsContent.Controls.Add(lb);
        x++;
    }
    Session[SESSION_KEY_HELPDESKLIST] = active;
}

void RegenerateHelpdeskSystems()
{
    List<HelpdeskSysEO> active = (List<HelpdeskSysEO>)Session[SESSION_KEY_HELPDESKLIST];
    int x = 0;
    foreach (HelpdeskSysEO hd in active)
    {
        LinkButton lb = new LinkButton();
        lb.ID = "lnkhd_" + x;
        lb.CommandArgument = hd.ID.ToString();
        lb.CommandName = "btnHelpdesk";
        lb.Attributes.Add("class", "lnkhelpdesk roundcor bluebtn");
        lb.Command += btnHeldesk_Command;
        HtmlGenericControl img = new HtmlGenericControl("img");
        if(!string.IsNullOrEmpty(hd.ImageIcon))
            img.Attributes.Add("src", "images/icons/" + hd.ImageIcon);
        else
            img.Attributes.Add("src", "images/icons/default.png");
        HtmlGenericControl span = new HtmlGenericControl("span");
        span.InnerText = hd.HelpdeskName.Replace("Helpdesk","").Replace("HELPDESK","").Replace("helpdesk","");
        lb.Controls.Add(img);
        lb.Controls.Add(span);
        divHelpdeskSystemsContent.Controls.Add(lb);
        x++;
    }

这是命令事件:

void btnHeldesk_Command(object sender, CommandEventArgs e)
{
    if (Globals.GetCurrentUser() != null)
    {
        if (e.CommandName == "btnHelpdesk")
        {
            HelpdeskSysEO hd = new HelpdeskSysEO();
            if (hd.load(int.Parse(e.CommandArgument.ToString())))
            {
                Globals.SetCurrentHelpdesk(hd);
                Response.Redirect("Home.aspx");
            }
        }
    }
}

我的页面加载:

protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostback)
   {
       //Checking session here
   }
}

0 个答案:

没有答案