Why do my session values return to nothing on post back?
I want to click a button and have the row, as in: dataset.table(0 ).rows(THIS
ROW NUMBER IS WHAT I AM TALKING ABOUT), either increment or decrement to
facilitate a movenext and movelast. I have been pulling my hair out and am
at the end of my rope.
PLEASE, how should I implement this? I have tried everything I can think
of, which really isn't much considering I am just beginning my forray into
vb.net programming. I have included all of my code.
I think that I am almost there, (I think) I just need to understand why my
session variables (in the IncrementRow and DecrementRow functions) keep
getting set to zero on post back. The Session("Applic antID") in the
page_load sub is persistant and that session variable is set from another
page, entirely!!!!
Public Class applicantactivi ty
Inherits System.Web.UI.P age
Protected WithEvents btnSaveFile As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnEditPersonRe cord As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnNewPersonRec ord As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnNewCompanyRe cord As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnClientActivi ty As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnApplicantAct ivity As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents txtAppInfoURL As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAppInfoEmail As
System.Web.UI.W ebControls.Text Box
Protected WithEvents Label12 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label11 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoFax As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAppInfoPhone As
System.Web.UI.W ebControls.Text Box
Protected WithEvents Label10 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label9 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label8 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label7 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoSigOt her As
System.Web.UI.W ebControls.Text Box
Protected WithEvents Label6 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoRegio nLong As
System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAppInfoRegio nCode As
System.Web.UI.W ebControls.Text Box
Protected WithEvents Label5 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoCount ry As
System.Web.UI.W ebControls.Text Box
Protected WithEvents Label4 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoCity As System.Web.UI.W ebControls.Text Box
Protected WithEvents Label3 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoAddre ss2 As
System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAppInfoAddre ss1 As
System.Web.UI.W ebControls.Text Box
Protected WithEvents Label2 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoMI As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAppInfoFirst Name As
System.Web.UI.W ebControls.Text Box
Protected WithEvents pnlAppInfo As System.Web.UI.W ebControls.Pane l
Protected WithEvents TextBox2 As System.Web.UI.W ebControls.Text Box
Protected WithEvents TextBox1 As System.Web.UI.W ebControls.Text Box
Protected WithEvents Label1 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label13 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label14 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label15 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtActivityDate As
System.Web.UI.W ebControls.Text Box
Protected WithEvents btnBOF As System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnPrev As System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnNext As System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnEOF As System.Web.UI.W ebControls.Imag eButton
Protected WithEvents pnlDashBoard As System.Web.UI.W ebControls.Pane l
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region
Protected AppActivityPage Title As
System.Web.UI.H tmlControls.Htm lGenericControl
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
AppActivityPage Title.InnerText = "AppActivit y - " &
Session("Applic antFullName")
If Not Page.IsPostBack Then
Dim ApplicantActivi tyDS As DataSet
ApplicantActivi tyDS =
GetApplicantAct ivity(Session(" ApplicantID"))
Session("Curren tRow") = 0
FillApplicantSc reen(ApplicantA ctivityDS, Session("Curren tRow"))
End If
End Sub
Function GetApplicantAct ivity(ByVal ApplicantID As String)
Dim SqlCon As New SqlClient.SqlCo nnection()
Dim DA As New SqlClient.SqlDa taAdapter()
Dim SqlCmd As New SqlClient.SqlCo mmand()
Dim ApplicantActivi tyDS As New DataSet()
Dim SQLSelectStatem ent As String
Dim ColumnNames As String
Dim FromClause As String
Dim WhereClause As String
Dim OrderClause As String
SqlCon = SqlQueryLibrary .BuildQuery.SQL Connect("server ", "user",
"pass", "database")
SqlCmd.CommandT imeout = 60
ColumnNames = "*"
FromClause = "ApplicantActiv ity"
WhereClause = "Applicant_ ID= " & ApplicantID
OrderClause = "date desc"
ApplicantActivi tyDS = SqlQueryLibrary .SQlSelect.Sele ctThis("server" ,
"user", "pass", "database", ColumnNames, FromClause, WhereClause,
OrderClause, ApplicantActivi tyDS)
Return ApplicantActivi tyDS
End Function
Sub FillApplicantSc reen(ByVal ApplicantActivi tyDataset As DataSet, ByVal
RowNumber As Integer)
txtActivityDate .Text =
ApplicantActivi tyDataset.Table s(0).Rows(RowNu mber).Item(16). ToString
End Sub
Private Sub btnNext_Click(B yVal sender As System.Object, ByVal e As
System.Web.UI.I mageClickEventA rgs) Handles btnNext.Click
Dim rownumber As Integer = IncrementRow()
Dim ApplicantActivi tyDS As DataSet
ApplicantActivi tyDS = GetApplicantAct ivity(Session(" ApplicantID"))
FillApplicantSc reen(ApplicantA ctivityDS, rownumber)
End Sub
Function IncrementRow()
Dim rownumber As Integer = Session("Curren tRow") + 1
Session("Curren tRow") = rownumber
Return rownumber
End Function
Function DecrementRow()
Dim rownumber As Integer = Session("Curren tRow") - 1
Session("Curren tRow") = rownumber
Return rownumber
End Function
End Class
I want to click a button and have the row, as in: dataset.table(0 ).rows(THIS
ROW NUMBER IS WHAT I AM TALKING ABOUT), either increment or decrement to
facilitate a movenext and movelast. I have been pulling my hair out and am
at the end of my rope.
PLEASE, how should I implement this? I have tried everything I can think
of, which really isn't much considering I am just beginning my forray into
vb.net programming. I have included all of my code.
I think that I am almost there, (I think) I just need to understand why my
session variables (in the IncrementRow and DecrementRow functions) keep
getting set to zero on post back. The Session("Applic antID") in the
page_load sub is persistant and that session variable is set from another
page, entirely!!!!
Public Class applicantactivi ty
Inherits System.Web.UI.P age
Protected WithEvents btnSaveFile As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnEditPersonRe cord As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnNewPersonRec ord As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnNewCompanyRe cord As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnClientActivi ty As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnApplicantAct ivity As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents txtAppInfoURL As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAppInfoEmail As
System.Web.UI.W ebControls.Text Box
Protected WithEvents Label12 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label11 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoFax As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAppInfoPhone As
System.Web.UI.W ebControls.Text Box
Protected WithEvents Label10 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label9 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label8 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label7 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoSigOt her As
System.Web.UI.W ebControls.Text Box
Protected WithEvents Label6 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoRegio nLong As
System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAppInfoRegio nCode As
System.Web.UI.W ebControls.Text Box
Protected WithEvents Label5 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoCount ry As
System.Web.UI.W ebControls.Text Box
Protected WithEvents Label4 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoCity As System.Web.UI.W ebControls.Text Box
Protected WithEvents Label3 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoAddre ss2 As
System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAppInfoAddre ss1 As
System.Web.UI.W ebControls.Text Box
Protected WithEvents Label2 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAppInfoMI As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAppInfoFirst Name As
System.Web.UI.W ebControls.Text Box
Protected WithEvents pnlAppInfo As System.Web.UI.W ebControls.Pane l
Protected WithEvents TextBox2 As System.Web.UI.W ebControls.Text Box
Protected WithEvents TextBox1 As System.Web.UI.W ebControls.Text Box
Protected WithEvents Label1 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label13 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label14 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label15 As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtActivityDate As
System.Web.UI.W ebControls.Text Box
Protected WithEvents btnBOF As System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnPrev As System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnNext As System.Web.UI.W ebControls.Imag eButton
Protected WithEvents btnEOF As System.Web.UI.W ebControls.Imag eButton
Protected WithEvents pnlDashBoard As System.Web.UI.W ebControls.Pane l
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region
Protected AppActivityPage Title As
System.Web.UI.H tmlControls.Htm lGenericControl
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
AppActivityPage Title.InnerText = "AppActivit y - " &
Session("Applic antFullName")
If Not Page.IsPostBack Then
Dim ApplicantActivi tyDS As DataSet
ApplicantActivi tyDS =
GetApplicantAct ivity(Session(" ApplicantID"))
Session("Curren tRow") = 0
FillApplicantSc reen(ApplicantA ctivityDS, Session("Curren tRow"))
End If
End Sub
Function GetApplicantAct ivity(ByVal ApplicantID As String)
Dim SqlCon As New SqlClient.SqlCo nnection()
Dim DA As New SqlClient.SqlDa taAdapter()
Dim SqlCmd As New SqlClient.SqlCo mmand()
Dim ApplicantActivi tyDS As New DataSet()
Dim SQLSelectStatem ent As String
Dim ColumnNames As String
Dim FromClause As String
Dim WhereClause As String
Dim OrderClause As String
SqlCon = SqlQueryLibrary .BuildQuery.SQL Connect("server ", "user",
"pass", "database")
SqlCmd.CommandT imeout = 60
ColumnNames = "*"
FromClause = "ApplicantActiv ity"
WhereClause = "Applicant_ ID= " & ApplicantID
OrderClause = "date desc"
ApplicantActivi tyDS = SqlQueryLibrary .SQlSelect.Sele ctThis("server" ,
"user", "pass", "database", ColumnNames, FromClause, WhereClause,
OrderClause, ApplicantActivi tyDS)
Return ApplicantActivi tyDS
End Function
Sub FillApplicantSc reen(ByVal ApplicantActivi tyDataset As DataSet, ByVal
RowNumber As Integer)
txtActivityDate .Text =
ApplicantActivi tyDataset.Table s(0).Rows(RowNu mber).Item(16). ToString
End Sub
Private Sub btnNext_Click(B yVal sender As System.Object, ByVal e As
System.Web.UI.I mageClickEventA rgs) Handles btnNext.Click
Dim rownumber As Integer = IncrementRow()
Dim ApplicantActivi tyDS As DataSet
ApplicantActivi tyDS = GetApplicantAct ivity(Session(" ApplicantID"))
FillApplicantSc reen(ApplicantA ctivityDS, rownumber)
End Sub
Function IncrementRow()
Dim rownumber As Integer = Session("Curren tRow") + 1
Session("Curren tRow") = rownumber
Return rownumber
End Function
Function DecrementRow()
Dim rownumber As Integer = Session("Curren tRow") - 1
Session("Curren tRow") = rownumber
Return rownumber
End Function
End Class
Comment