In ASP. net, panel server controls are generally used as container controls to hide and display widgets in groups. In most cases, you can directly set the Panel's visualable attribute to true or false, however, in some cases, for example, when the entire page is validate, but in a hidden panel, there is the requiredvalidate control, which verifies that the control is hidden together with the Panel, therefore, it cannot pass the verification. Therefore, the page's validate cannot pass because of a validate control. The original intention is that hidden controls do not need to be verified.
To solve this problem, you need to find all the validate sub-controls in the Panel when hiding the panel, telling them that they can be ignored during the validate operation, and re-setting when displaying the panel.
This method consumes more resources than directly hiding or displaying the panel control. Therefore, you need to use it in different situations. If the Panel does not have a verification control, you can directly hide or display the panel control. If there is a verification control in the panel, it is best to use this article to hide or display it.
This sectionCodeUse the. NET Framework SDK sample duwamish directly.
' ----------------------------------------------------------------
' Sub showpanel:
' Helper sub used to make certain that the validators do not
' Fire when their parent panel is not visible.
' ----------------------------------------------------------------
Public Shared Sub showpanel () Sub Showpanel ( Byref Panel As Panel, Byval Visible As Boolean )
Dim Validator As Ivalidator
Dim CTRL As Control
For Each CTRL In Panel. Controls
' Check to see if its A validator
If Typeof CTRL Is Ivalidator Then
Validator = Ctype (CTRL, ivalidator)
CTRL. Visible = Visible
If Not Visible Then
Validator. Validate ()
End If
End If
Next
Panel. Visible = Visible
End sub