简体   繁体   English

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

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

Does FindControl() work quick or not? FindControl()是否可以快速运行?

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. FindControl(我认为)通过所有控件循环,因此速度取决于控件的数量。 I think you shouldn't worry. 我想你不用担心。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在findcontrol中使用数组吗? - Can I use an array in findcontrol? 如果我有一个返回AsEnumerable的函数,它会缓存所有结果吗? - If I have a function that returns AsEnumerable, does it cache all result? 当我想要具有相同名称的控件时,如何处理“ FindControl要求控件具有唯一的ID”? - How do I handle “FindControl requires that controls have unique IDs” when i want controlls with the same name? 当我给它扫描的行时,为什么findcontrol需要唯一的id - Why does findcontrol need unique id, when I have given it the row to scan 如果我有重复的次数,如何重复一个字符组成一个字符串? - How can I repeat a character to make up a string if I have a number for the times to repeat? 我如何在不使用FindControl()方法的情况下,在后面的代码中使用位于gridView中的文本框的值 - How I can use the value of a textbox which is in a gridView in the code behind without using the FindControl() method 我们总是需要使用 context.Server.MapPath 吗? 如果我缓存结果怎么办? - Do we always need to use context.Server.MapPath? what if I cache the result? 我有链接,我想计算每个链接被点击的次数,并使用 asp.net mvc5 将此计数保存在数据库中 - I have links I want to count the number of times each link is clicked by and save this counting in database using asp.net mvc5 尽管数据表存储在缓存中,但每次使用后我都必须调用dispose吗? - Do I have to call dispose after each use though datatable is stored in cache? 使用FindControl(“”)的简便方法 - Easy way to use FindControl(“”)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM