controls.contains?

  • Thread starter Thread starter djc
  • Start date Start date
D

djc

<snippet from .net documentation>
If Panel1.Controls.Contains(NewPanelButton) Then
RemoveHandler NewPanelButton.Click, AddressOf _
NewPanelButton_Click
Panel1.Controls.Remove(NewPanelButton)
NewPanelButton.Dispose()
End If
</snippet from .net documentation>

I need to be able to first check if a control exists within a panel and take
action based on its existence. The above method seems like it would fit the
requirement but I get a compile error "Name nameOfControl is not declared".
It seems this method is meant to see if a control 'contains' another control
so how can it be required for the control name passed in to exist first? The
control I need to check for is dynamically created and thats why I need to
check for its existance in the first place. So it may or may not exist????

????
 
Even if it's dynamically created, surely the variable that references the
control is declared on the aspx page somewhere, giving all methods within
the containing class access to it.
 
yes, a declaration for the control does exist but it is inside an IF / End
If conditional block. It is only declared if its needed. Thats the whole
reason I need a method to see if it exists. Its part of a type of cleanup
routtine that 'resets' controls in a panel. I am dynamically removing/adding
controls for editing data. Looks real good but its becoming a major pain. I
assume due to my lack of experience with asp.net. I have changed my approach
to just manipulating the Visible property and ditched dynamically creating
the controls. But I would still like to understand this.

thanks for the reply.
 
Back
Top