Best way to find a control on a page?
We have a control that contains an updatepanel. When updating this panel and doing a partial page update we also need to update a separate control that is in the page template. What's the best of finding this control?
(in this example we are talking about a custom product detail page, and updating a mini-basket
(also a custom control) on the template when someone clicks adds to basket (also a custom control)).
Hello Nick,
Could you please give us more details about your question - do you want to find the control from client-side code or server-side code? For server-side code you could assign a code-behind class to your page and use Page.FindControl or simply reference the control in the page. For client-size if you know the ID of your control you could use either some jQuery selector or the Microsoft AJAX $find() or $get() functions.
All the best,It would be server side. I was going to go with the recursive lookup approach using .FindControl, but just wondered if Sitefinity had it's own internal mechanism for maintaining a list of controls. In previous applications we've built we've had our own custom base page class which we've used to maintain a reference to a specific control - the control registers itself with the page base class during init, so that other controls can then reference it from the base class without the recursive overhead of using FindControl each and every time. I'm not sure if this is doable in SF? Is it possible to use a custom page base class? Or I guess we could do it on the master page if not.
Hello Nick,
Please check the following blog post -
http://www.sitefinity.com/blogs/petermarinov/posts/11-12-27/sitefinity_and_the_asp_net_code-behind_model.aspx
It outlines how to implement a custom code-behind class for your page where you can use the FindControl method to retrieve a reference to a page control.
Thanks, that looks to be exactly what I was after.