开发者

Part of custom control should be rendered only once

开发者 https://www.devze.com 2023-02-14 23:23 出处:网络
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 i

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 h开发者_Python百科elp would be great.

Thanks, Surya


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消