More in this section

Forums / Developing with Sitefinity / Best way to find a control on a page?

Best way to find a control on a page?

5 posts, 1 answered
  1. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    01 Feb 2012
    Link to this post
    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)).
  2. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    02 Feb 2012
    Link to this post
    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,
    Lubomir Velkov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    02 Feb 2012
    Link to this post
    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.
  4. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    06 Feb 2012
    Link to this post
    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.

    Kind regards,
    Lubomir Velkov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  5. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    06 Feb 2012
    Link to this post
    Thanks, that looks to be exactly what I was after.
5 posts, 1 answered