By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

can't seem to hide user control with code

P: n/a
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.
Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
So this is a user control you've created?
If so, you probably need to implement your own version of the visible
property and put code similar to this in it:

For each ctrl as Control in Me.Controls
ctrl.Visible=Value
Next

Here's more info:
http://SteveOrr.net/faq/ControlTreeRecursion.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.com...
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.

Nov 19 '05 #2

P: n/a
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

"Steve C. Orr [MVP, MCSD]" wrote:
So this is a user control you've created?
If so, you probably need to implement your own version of the visible
property and put code similar to this in it:

For each ctrl as Control in Me.Controls
ctrl.Visible=Value
Next

Here's more info:
http://SteveOrr.net/faq/ControlTreeRecursion.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.com...
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.


Nov 19 '05 #3

P: n/a
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.

Nov 19 '05 #4

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

"sam" wrote:
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.

Nov 19 '05 #5

P: n/a
just put an asp:panel around the user control and hide that when needed.

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.com...
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.

Nov 19 '05 #6

P: n/a
Sounds like a good idea. Thanks.
--
Paul G
Software engineer.
"Tarren" wrote:
just put an asp:panel around the user control and hide that when needed.

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.com...
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.


Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.