Home
 Index > ASP.NET Web Applications > Web Control visibility property not consistent ...

ASP.NET Web Applications:  Debugging

Web Control visibility property not consistent with its visibility when a page loads

When debugging code, the "visible" property shows "false" for a Web Control even though the control is visible in the browser before and after the page loads.

Added on 3 Jun 2008

Scenarios:

Scenario Summary:
Web Control visibility property not consistent with its visibility when a page loads.
Scenario Details:

A Web Control is visible when the page loads and visible again on postback, but when debugging code, the control's visibility property is set to False.

A method call should fire if the control is visible when a button is clicked, but since the property is not set correctly, the method is not called.

Added on 3 Jun 2008

Solution Summary:
Ensure that all parent controls are visible when calling the desired control.
Solution Details:

When a control's visibility property is set to true, it will only be visible if all parent controls that contain it also have their visiblity set to true.

  • Turn on trace to view the control hierarchy. 

    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="MyPage.aspx.vb" Trace="true" Inherits="DevCorner.MyPage"%>

  • Add a literal to the page and output the visibility property values for each of the parent cotrols for each event that modifies the visibility property of any of these controls.

    Private Sub btnTopic_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTopic.Click
         trTopics.Visible = ddlArea.SelectedIndex > 0
         pnlTopics.Visible = cblTopics.Items.Count > 0
         Dim s As String = "<B>settopicvisible:</B> <BR>pnlIssueForm: " & pnlIssueForm.Visible.ToString
         s &= "<BR>trTopics: " & trTopics.Visible.ToString
         s &= "<BR>pnlTopics: " & pnlTopics.Visible.ToString
         s &= "<BR>cblTopics: " & cblTopics.Visible.ToString
         Literal1.Text = Literal1.Text & "<BR>" & s
    End Sub

    When events such as the button click above fire, they will concatenate with the literal string.  This will display the different visibility properties for each of the controls after each of the relevant events fire.

Was this solution useful? Yes No Added on 3 Jun 2008
Rating: 

Copyright 2010 © E-Centric, Inc. | Terms of Use