+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Access (or pass) value from page template to user control

Access (or pass) value from page template to user control

4 posts, 0 answered
  1. Barry
    Barry avatar
    8 posts
    Registered:
    30 Dec 2010
    19 May 2011
    Link to this post
    Hello -

    I am trying to determine a method for exposing a value generated on a page template to a user control that is placed on a page from the toolbox.  My specific scenario is that I must generate a unique ID to be used by javascript on the master page that flows to our analytics software.  I must also ensure that this unique ID flows to backend systems so that we can correlate the data at a later point in time.  The analytics is taken care of on the master page but the insertion in to the backend system is handled in a user control.

    Is there  a way to access a custom property on a master page template from within a user control or "pass" a value to a user control?  The requirements are that the user control must be able to be added through the page designer dynamically from the toolbox.

    Currently, my master page inherits from System.Web.UI.MasterPage and lives in ~/App_Master.  My user control inherits from System.Web.UI.UserControl and lives in ~/UserControls.  The only solution that I've been able to come up with so far is to store the value required in Session and then retrieve it in the user control but I have to think there is a better way to do this.  I am using Sitefinity 3.7.

    Thank you in advance for any assistance!

    Regards,

    Barry
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    20 May 2011
    Link to this post
    Hi Barry,

    You can use session, cookie or query strings. There is a way to persist the data into the database, but this means that you will make transaction on each request.

    Kind regards,
    Ivan Dimitrov
    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. Barry
    Barry avatar
    8 posts
    Registered:
    30 Dec 2010
    20 May 2011
    Link to this post
    Hello Ivan -

    Thank you for the quick response.

    Just to confirm, there is no way to gain access to the master page template that a control resides in from within the control itself (e.g. inherit from different class, implement additional interface, etc.)?  If not, is this something that is exposed in 4.x or planned for future versions?

    Regards,

    Barry
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    25 May 2011
    Link to this post
    Hi Barry,

    From the control you can use Page property to get access to the template. If there are nested pages you need to loop until you reach the the page template.

    Kind regards,
    Ivan Dimitrov
    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
Register for webinar
4 posts, 0 answered