More in this section
Forums / Developing with Sitefinity / Passing variables between Modules

Passing variables between Modules

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Trevor
    Trevor avatar
    17 posts
    18 Nov 2010
    27 Jan 2011
    Link to this post
    I currently have an advert control which displays adverts fetched from a marketing service. The advert control uses an ID which references an ad on the marketing service's server which is then displayed on the website. So far no problem... but in order to boost performance we are now streamlining the process (since you can have multiple ads per page) whereby an Advert Manager control will request all the adverts in one request (instead of each advert control requesting independently) and then having the placed advert controls use the already requested data to render their ads.

    Now the problem is that I need to communicated the ID from the advert controls to the advert manager and here I am having a bit of trouble.

    I am trying to pass the advert ID from:

    protected override void InitializeControls(Control controlContainer)
                //Advert ID code


    HttpContext.Current.Items["AdID"] = AdvertID;

    to the Advert Manager control's prerender state (since I need to render the Advert Manager AFTER the controls have been render):

    protected override void OnPreRender(EventArgs e)
        AdvertManager.Text = (string)(HttpContext.Current.Items["AdID"]);

    The problem is that the Advert Manager ends up rendering empty. Since it seems the PreRender triggers after the InitializeControls.

    As soon as I test a value from: protected override void OnInit(EventArgs e) it passes correctly since that definitely renders earlier in the page life cycle.

    I would really appreciate any pointers with this, since somewhere along the life cycle I'm rendering one part to early or the other part to late.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    27 Jan 2011
    Link to this post
    Hi Trevor,

    Generally it depends on how the control are positioned on your page. If the control where you call InitializeControls is positioned above the control where you call OnPreRender, then InitializeControls will be called before OnPreRender on the second control.

    When InitializeControls and OnPreRender are in the same control, first InitializeControls is called and then OnPreRender.

    When the control where you call OnPreRender is above the control where you call InitializeControls, first OnPreRender is executed and then InitializeControls of the second control.

    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered