Well, you are using properties (which will be reset each time the page
loads) and ViewState (which will persist) when all you really need is
ViewState and forget the properties all-together. You are making your code
more difficult than it need be.
In the spots where you want to store data for the next page call, just put
that data directly into ViewState and forget the properties. When you need
the data, just pull it out of ViewState.
How about this:
Private Sub Page_Load( . . .) Handles MyBase.Load
If Not IsPostBack Then
setValues() --> Setting basic values
SPOpType = Request.QueryString("optype")
If Not SPOpType = "" Then
getDetails()
makeVisible() --> Making Panels Visible
Else
makeInvisible() --> Making Panels InVisible
End If
End If
End Sub
Private Sub btnGrid_Click( . . . ) Handles btnGrid.Click
Dim dsCompare As DataSet
'No need to cast thse text values since they will become objects in
ViewState anyway
ViewState.Add("SPItemNumber", txtEVID.Text)
ViewState.Add("SPSaleDate", txtSDate.Text)
Try
' DOES db.GetCompare() ON THE NEXT LINE RETURN A DATASET?
' If not, then dsCompare is not going to be instantiated as a
NEW dataset.
dsCompare = db.GetCompare(CType(txtEVID.Text, Integer),
Ctype(txtSDate.Text, Date))
If Not dsCompare Is Nothing Then
ViewState.Add("SPDGCompare", dsCompare)
dgCompare.DataSource = dsCompare
dgCompare.DataBind()
pnlCompare.Visible = True
End If
Catch ex As Exception
errLog.LogIt("Binding Compare Grid Error", ex, "")
End Try
End Sub
Private Sub getDetails()
Dim ds As DataSet
Dim dsSum As DataSet
Dim SPItemNumber As Integer = CType(ViewState("SPItemNumber",
Integer))
Dim SPSaleDAte As Date = CType(ViewState("SPSaleDate", Date))
Try
dgCompare.DataSource = CType(ViewState("SPDGCompare") , DataSet)
dgCompare.DataBind()
Catch ex As Exception
errLog.LogIt("Binding Grid1 Error", ex, "")
End Try
ViewState.Add("SPItemNumber", txtEVID.Text)
ViewState.Add("SPSaleDate", txtSDate.Text)
Try
ds = db.GetDetails1(SPItemNumber, SPSaleDate, SAPOpType)
dgScroll.DataSource = ds
dgScroll.DataBind()
Catch ex As Exception
errLog.LogIt("Binding Grid2 Error", ex, "")
End Try
Try
dsSum = db.GetDetails2(SPItemNumber, SPSaleDate, SAPOpType)
dgSummary.DataSource = dsSum
dgSummary.DataBind()
Catch ex As Exception
errLog.LogIt("Binding Grid3 Error", ex, "")
End Try
End Sub