Share data with blocks in webforms



I have an episerver page with a contentarea. Each of the blocks that goes into the content area are quite data heavy, so i would like to share data from the page to the blocks in the content area. I know this is quite easy to achieve in MVC using the Html.PropertyFor helper. But what are my options in WebForms, while still maintaing on-page edit and support for rendersettings tags ?

Currently i have the following suggestions :

  • Using the Episerver:ContentRenderer control instead of the episerver:property control. Getting the item from the contentarea and setting the CurrentData on the episerver:contentrenderer control
  • Make the page store the data in HttpContext.Current.Items and reading this in the block

Do you have any other suggestions on how to achieve this ?

Feb 01, 2016 13:30

If the data is expensive to get from the data source, it's probably worth using cache like the ISyncronicedObjectCache

to store your expensive data. You could of course only use the HttpContext to store the expensive data during the request but if you have many users that will still result in a performance problem since every new request will require getting the data again.

Using EPiServers caching will also help if you later decide to load balance your solution

Feb 01, 2016 13:53

You can do the same in webforms. This is how you pass data with the property webcontrol, you can also do it code-behind if you want to do it in a more typed way:

<EPiServer:Property PropertyName="YourContentArea" runat="server">
    <RenderSettings YourPropertyThatWillEndUpInRenderSettings="TheData" />

Then from your view's code-behind you can get the property by calling:

Feb 01, 2016 21:45

Hey Johan,

The few experiments i have done with that method, suggests that only string values can be passed that way is that correct ? i could of course serialize the data to json.

Feb 02, 2016 8:00


If you want to pass values arround in the UI they must be serialized, but technically you can pass anything in the RenderSettings dictionary. This is however not just a problem in webforms, you have the same issue in mvc.
In this case you could pass the page id and then load it in the block. You have the current page object in the block, but it will be the startpage when the block is re-rendered when e.g. an editor changes anything.

This might be an XY problem, What are you really trying to achieve here? Having blocks dependent on the page they're rendered on usually ends up with problems.

Feb 02, 2016 10:06
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.