2

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?

4 Answers 4

2

Most controls have a Visible property.

In your code-behind set this to False in order for it to not display:

myCtrl.Visible = false;
Sign up to request clarification or add additional context in comments.

Comments

2
control.Visible = false;

2 Comments

So in the code behind for the .ascx I can refer to itself and tell it not to be visible?
Yes, you could do this.Visible = false;
1

Try:

this.Visible = false;

From within your ascx.cs codebehind file.

Comments

0

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.

1 Comment

I tried using this method, despite the studies was failing. In the end, I had to use the method visible = true/false @SoftwareGeek

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.