Well, I see that in your Page_Load event you aren't doing anything when it
IS a postback. So it would seem that on the first page call you'd get the
page and after that, you'd get absolutely nothing. Make sure to either turn
off the ViewState (EnableViewState property) for each panel so that they
always start out being invisible or add code to your IsPostBack that shuts
off the last panel.
I think it should be (I've also cleaned up your code a bit):
---------------------------------------------------------------------------
Imports System.Configuration
Imports System.Data.OleDB
Public Class Questions2
Protected WithEvents CAD As System.Web.UI.WebControls.panel
Protected WithEvents CHF As System.Web.UI.WebControls.panel
Protected WithEvents HB As System.Web.UI.WebControls.panel
Protected WithEvents DBTS As System.Web.UI.WebControls.panel
---------------------------------------------------------------------------
Public Sub Page_Load(Source As Object, E As System.EventArgs)
If Not IsPostBack Then
'Page is loading for first time
'Show whatever the user is supposed to see on the first page load
Else
'Page is loading in response to the form being submitted
'Figure out which questions to show them next
GetQuestions()
End If
End Sub
---------------------------------------------------------------------------
Public Sub GetQuestions()
Dim strbarConn as string = _
ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_cardmemberoledb")
Dim strbarSQL as String = "SELECT ProgramID, QuestionHTML " & _
"FROM SponsorQuestions WHERE
SponsorID = '" & _
Session("SponsorCode") & "'
ORDER BY QuestionCode"
Dim objBarConnection as New OledbConnection(strbarConn)
Dim objBarCommand as New OledbCommand(strBarSQL, objBarConnection)
Try
objBarConnection.open()
Dim objBarDataReader as OledbDatareader =
objBarCommand.ExecuteReader()
Do While objBarDataReader.Read
' response.write(strbarSQL)
Dim ctl as Control
For Each ctl In Controls
Response.Write(ctl)
If TypeOf (ctl) Is Panel Then
If ctl.ID = objBarDataReader("ProgramID") Then
ctl.visible = True
End If
End If
Next
Loop
Catch ex As OleDBException
'Handle exceptions here
Finally
objBarDataReader.Close()
objBarConnection.Close
End Try
End Sub