开发者

How to add or not a control in a aspx page?

I have a page with a web user control, this one is quite heavy and he is used only if the application user have some rights. So he is set to visible = false in case of user can't use it.. But in this case the control is added to page even he is not visible.

The problem is the web user control is used 开发者_运维知识库really Rarely. So I would like to not include code if this is not necessary. I feel I have to use the preinit state to add the web user control when it is necessary but I don't know how.. Any good idea? Thanks for help..


add it in the code behind with LoadControl, eg. put PlaceHolder on that aspx page and then load it from the code, like this

if (something)
{
  Control cnt = Page.LoadControl("UserControl.ascx");
  placeHolder1.Controls.Add(cnt);
}


What do you mean with quite heavy? If it it time consuming because of its databinding, you should provide a public function(f.e. BindData) that is not called automatically from page_load but from the page when it is requested and the user is authorized to see.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜