开发者

Problem with Session unpack

I have some problems with this code:

    private v开发者_Python百科oid BoxVisibility(bool email, bool link, Control linkButton)
    {
        mainEmail.Visible = email;
        foreach (Control c in PlaceHolder1.Controls)
        {
            c.Visible = false;
        }
        if (linkButton != null)
        {
            PlaceHolder1.Visible = true;
            linkButton.Visible = link;
        }

    }

when I send to method Control all is ok, but when at first I put Control in Session['temp'] = Control, and then invoke the method like BoxVisibility(false, true, (Control) this.Session['temp']) in this case Control linkButton.Visible = link; doesn't take true, He's still remain false.


The "control" is a reference to a particular instance for this particular page.

The Page is recreated on every request, so a reference to an old instance of your control is no longer valid. So don't store controls in anything (Session, ViewState, static fields) that lives longer than the single request. Local (instance) fields of your page are safe.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜