开发者

Have I to cache FindControl() result if I use it a number of times?

开发者 https://www.devze.com 2022-12-11 10:23 出处:网络
Does FindControl(开发者_开发技巧) work quick or not? Have I to cache a result using a property like this or not if I search and use the same control a number of time?

Does FindControl(开发者_开发技巧) work quick or not?

Have I to cache a result using a property like this or not if I search and use the same control a number of time?

private MyUserControl c;
private MyUserControl MyC
{
    get
    {
        if(c == null)
            c = (MyUserControl)FindControl("c");
        return c;
    }
}


If you're talking across requests then don't. You can't in fact. Control references only exist temporarily while the page is rende Putting them in session or some other persistent cache let's them persist and screws up the garbage collector


every question with 'is it quick' should be answered: try it out.

FindControl (i think) loops trough all the controls therefor the speed is depended on the amount of controls. I think you shouldn't worry.

0

精彩评论

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

关注公众号