Hello all,
I have the following situation. I have a user control embedded in a web form that has a panel on it. Within the panel, there are other multiple user controls with their initial visibility set to false. When the user clicks on a link in the web form, I want it to set the visibility to true for a prticular user control in the panel. This works fine.
However, what I wanted to do is loop through all controls in the panel when the user clicks the linkbutton and set their visibility to off. I then locate the user control in question and set its visbility to on. This is where I'm having an issue. Here is the code I am using in the linkbutton, which is on the user control on the web form.
Dim myuc As UserControl = New UserControl
For Each myuc In Me.Controls
myuc.Visible = False
Next myuc
myuc = Me.FindControl("ucsub_x22release")
myuc.Visible = True
The error I get is this:
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 57: Private Sub lnk_contactnds_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnk_contactnds.Click
Line 58: Dim myuc As UserControl = New UserControl
Line 59: For Each myuc In Me.Controls
Line 60: myuc.Visible = False
Line 61: Next myuc
Source File: C:\Inetpub\wwwroot\xweb\corpinfo.ascx.vb Line: 59
Can anyone point me in the right direction on how to accomplish this?
Thanx in advance,
inzo
I have the following situation. I have a user control embedded in a web form that has a panel on it. Within the panel, there are other multiple user controls with their initial visibility set to false. When the user clicks on a link in the web form, I want it to set the visibility to true for a prticular user control in the panel. This works fine.
However, what I wanted to do is loop through all controls in the panel when the user clicks the linkbutton and set their visibility to off. I then locate the user control in question and set its visbility to on. This is where I'm having an issue. Here is the code I am using in the linkbutton, which is on the user control on the web form.
Dim myuc As UserControl = New UserControl
For Each myuc In Me.Controls
myuc.Visible = False
Next myuc
myuc = Me.FindControl("ucsub_x22release")
myuc.Visible = True
The error I get is this:
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 57: Private Sub lnk_contactnds_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnk_contactnds.Click
Line 58: Dim myuc As UserControl = New UserControl
Line 59: For Each myuc In Me.Controls
Line 60: myuc.Visible = False
Line 61: Next myuc
Source File: C:\Inetpub\wwwroot\xweb\corpinfo.ascx.vb Line: 59
Can anyone point me in the right direction on how to accomplish this?
Thanx in advance,
inzo