开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜