can't seem to hide user control with code

G

Guest

Hi I am trying to conditionally hide a user control on a form in the code.
There is a visible element in the properties box of the user control but in
the .vb file (in the code) the object does not seem available. Using me. the
intellsince does not show the user control name, so can not seem to get to
its properties in code.
Thanks.
Paul G
Software engineer.
 
G

Guest

Hi thanks for the response. It is a control that I created.
I tried the following but get a runtime error (Object reference is not set
to an instance of an object) when using
Imports projectname.usercontrolname '
Me.usercontrolname.Visible = False ' runtime error occures here.
I also set up the code below like what you had suggested which seems to run
ok but not sure if it is itterating through all of the controls on the form.
For Each ctrl As Control In Me.Controls
ctrl.Visible = True
Next
 
S

sam

I think asp.net for efficiency reasons creates 5 child controls, some
of which are null. So you need to insert into the foreach loop:
if(ctrl != null) { ctrl.Visible = True }

or however you write that in VB.
 
G

Guest

ok thanks for the information, think it would be
if ctrl <> NULL then
ctrl.visible = True
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top