Reputation: 85
Say I have a user control (.ascx) on a .aspx page. In the code behind on the .ascx is there a way to tell itself to not load if a certain condition was met?
I don't want to just not display this control by javascript or css, I need to do it in the codebehind.
Any thoughts?
Upvotes: 2
Views: 1610
Reputation: 15762
I would suggest to put the condition in the 'aspx' page that is loading the user control. So if you are calling LoadControl, you would surround it with the condition to make it available or otherwise.
You can also add a property say 'IsVisible' within the usercontrol and set visibility like others have suggested.
Upvotes: 0
Reputation: 498904
Most controls have a Visible
property.
In your code-behind set this to False
in order for it to not display:
myCtrl.Visible = false;
Upvotes: 2