error on findcontrol(MyPanel,panel)

P

Peter Kaufman

I am using the following code from ASP.NET Unleashed successfully in
an aspx page, but when I move it to a code behind page in VS I get
this error on the asterisked line when the code runs :

Private Sub btnNextPage_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnNextPage.Click
Dim pnlPanel As panel
Dim strPanelName As String

' Hide Previous Panel
strPanelName = "pnlForm" & ViewState("CurrentPage")
*pnlPanel = FindControl( strPanelName )
pnlPanel.Visible = False
End Sub

System.InvalidCastException: Specified cast is not valid
Line 65: pnlPanel = FindControl(strPanelName)

strPanelName is resolving to the string "pnlForm1".
I also tried: pnlPanel = CType(FindControl(strPanelName), panel) -got
the same error

Help appreciated!

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

FindControl problem 2
Findcontrol issue 0
GridViewRow FindControl failing 3
FINDCONTROL PROBLEM 1
problem with FindControl 2
FormView FindControl error 1
FindControl not working 11
Help with FindControl method 10

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top