hiding a user control

wsyeager

Centurion
Joined
Apr 10, 2003
Messages
140
Location
Weston, FL
I have a usercontrol which I would like to make invisible based on a certain condition as follows:


Protected SchedulingAdminLogout As New YTCIWebUserControls.SchedulingAdminLogout

.

.

.

If DirectCast(ViewState.Item("PCREntry"), String) = "1" Then

SchedulingAdminLogout.Visible = False

End If




While debugging, it does go inside the IF statement (which I'm expecting), but the user control remains visible on the webform. How can I set the visibility to false based on this condition?
 
Are you doing this in Page_Load? If you are setting the property too late, then the HTML is already rendered and the user control will be visible.
 
Robby, I have the following code in my page load event of the webform:

<code>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then
ViewState.Item("InitialTime") = DirectCast(Request.QueryString.Item("InitialTime"), String)
ViewState.Item("PCREntry") = DirectCast(Request.QueryString.Item("PCREntry"), String)
BindData()
End If

If DirectCast(ViewState.Item("PCREntry"), String) = "1" Then
Dim tblAdminSchedulingLogout As Table = SchedulingAdminLogout.FindControl("tblAdminSchedulingLogout")
tblAdminSchedulingLogout.Visible = False
End If

End Sub
</code>

Unfortunately, the tblAdminSchedulingLogout variable is still set to Nothing after executing the FindControl statement.

I have the following code in my usercontrol:
<code>
<table id="tblAdminSchedulingLogout" align="right" style="Z-INDEX: 103; LEFT: 750px; POSITION: absolute; TOP: 12px"
runat="server">
<tr>
<td><asp:Button id="btnMainMenu" runat="server" Text="Main Menu" CausesValidation="False"></asp:Button></td>
<td></td>
<td></td>
<td><asp:Button id="btnLogout" Text="Logout" runat="server" CausesValidation="False"></asp:Button></td>
</tr>
</table>
</code>

As you can see, I'm giving the table an ID. However, I still can't access the table from within my webform (as evidenced by the FindControl method).

I'm trying to set the table to invisible once I find the control. I don't know why I can't find the control??????
 
Back
Top