views:

74

answers:

2

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;
}
}
+2  A: 

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.

PoweRoy
+3  A: 

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

Simon_Weaver