开发者

How to hide a databound control

Depending on the case, I'd like to hide a databound control in a page. But no matter what I try, it seems like the control will try biding no matter what. I've tried setting Visible="false", but it would still try to bind. I've tried putting the control into a placeholder and then hide the placeholder, it will try to bind anyway. I've also tried putting it into a MultiView, same thing. You would think that in a wizard interface using a MultiView you would not want the controls in the next steps of the wizard to bind, but no. It binds anyway...

The only way I've found is to unset and set the DataSourceID property which seems to prevent binding.

Is开发者_JS百科 this really the only option?

Thank you.


I think that you are on a good path. Do not set the data source id. When it comes time to display the data (which I presume is triggered by a user click), explicitly databind your control.

when you set the datasourceid on your control, then the asp.net framework will automatically data bind when the page's OnDataBind event occurs.


Could it be that you're using a datasource control to bind to? The DataSourceID property being set indicates so. If you don't want it to bind to such a control you can opt to take out the DataSourceID property in markup and explicitely set it in codebehind only when you need it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜