Control.visible = true sets the visibility of a control to false

N

Nick Stansbury

Hi,

I have a loop running on Page_PreRender that sets a number of controls
to invisible based on a set of criteria. Before I do this however, I set all
of the drop down lists to be visible with a straightforward recursive loop.

Now - I'm really muddled by this - why does this:
If TypeOf Ctl Is DropDownList Then
Ctl.Visible = true
End If
Set the control to be INVISIBLE? How is this possible - I put a breakpoint
in at the first of these lines, evaluate ctl.visible, the debugger returns
"true", step forward one line, evaluate ctl.visible, still true, move on to
the third line, and now ctl.visible = false !!!!! How is this possible? Can
someone please help me? For now, I've created a css class called "invisible"
which uses css to set the control to invisible, but the effect isn't the
same and it's going to make the page a whole bunch bigger.
Any ideas?
Nick
 
K

Karl Seguin

I for one, need more context to solve this one...like seeing more of the
code...

Karl
 
N

Nick Stansbury

Hi,

The problem occurs in a custom page class here are the relevant
snippets:

Public Class Standard : Inherits System.Web.UI.Page

Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
ResolveDivDDLOverlayConflicts()
End Sub

Private Sub ResolveDivDDLOverlayConflicts()
'first set all Drop down lists to visible before performing analysis
For each ctl as Control in me.controls
_RecursivelySetDDLVisibility(Ctl, True)
next
End Sub

Private Sub _RecursivelySetDDLVisibility(ByVal Control as Control, ByVal
Visibility as boolean)
If TypeOf Control is DropDownList then 'Line A
Control.visible = Visibility 'Line B
end if 'Line C
For each SubControl in Control.Controls
_RecursivelySetDDLVisibility(SubControl, Visibility)
next
End Sub

So if I step through this and evaluate Control.Visible on the Line's marked
A,B & C then at A it's marked as true, at B it's marked at true (because B
hasn't yet been run) but at C it evaluates to false! And what's more if I
then in the immediate window I try to set it to true and then evaluate it
it's still false!

Nick
 
N

Nick Stansbury

Not sure what you mean when you refer to "shared variables at play" - could
you clarify?

Not as simple as you mentioned - I actually try it with a single user
control on a single page, with a single drop down list and a bunch of text
boxes - I'll try it without the user control.

Any other suggestions?

Nick
 
N

Nick Stansbury

Hi,

No - nothing like this.

Thanks for your help Karl - I'm going to call this strugle a day and leave
it. If I get to the bottom of it I'll post a solution (and a cause) back
here

Nick
 

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

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top