Surya Gudipati
Surya Gudipati

Reputation: 5

Part of custom control should be rendered only once

I am working on a custom control. Part of it is to render a div that is not displayed right away. Based on a particular client event, that div is shown. Everything works fine when there is only once instance of the custom control on a page. But in case of multiple instances, that many above mentioned divs are rendered, though not displayed. To make container page lighter, I basically want to render that div only once, irrespective of the number of occurrences of the custom control. Any help would be great.

Thanks, Surya

Upvotes: 0

Views: 161

Answers (1)

Atanas Korchev
Atanas Korchev

Reputation: 30661

Perhaps you can store a flag telling that that div has already been rendered. You can store that flag in HttpContext.Items. Here is some code

if ((bool)HttpContext.Current.Items["divRendered"] == false)
{
   //Render the div
   HttpContext.Current.Items["divRendered"] = true;
}

Upvotes: 2

Related Questions