如果多次使用 FindControl() 结果,是否需要缓存它?

发布于 2024-08-11 15:24:48 字数 273 浏览 2 评论 0原文

FindControl() 工作速度快吗?

如果我多次搜索并使用相同的控件,是否可以使用这样的属性来缓存结果?

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

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;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傾旎 2024-08-18 15:24:48

如果您正在谈论请求,那就不要这样做。事实上你不能。控制引用仅在页面渲染时暂时存在将它们放入会话或其他持久缓存中让它们持续存在并搞砸垃圾收集器

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

眼中杀气 2024-08-18 15:24:48

每个关于“快吗”的问题都应该得到回答:尝试一下。

FindControl(我认为)循环通过所有控件,因此速度取决于控件的数量。我认为你不应该担心。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文