sessions not working right
this should be simple, i've ran into it before, but can't remember how i fixed it.
I have a single page, that is just displaying other pages inside of it. It has a previous and a next button to page between the pages of a book. however, if you click next, then previous, it goes next twice, instead of going to the next one, and then going to the original one.
can anyone tell me what the problem is? I have the code below, and a working example at http://www.ori.net/mandreko/highscho...1/Default.aspx
Default.aspx:
Code:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Default.aspx.vb" Inherits="highschoolsports1._Default"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Default</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="VBScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<P>
<asp:Label id="lblPageNo" runat="server"></asp:Label><BR>
<asp:LinkButton id="hypPrevious" runat="server">Previous</asp:LinkButton>
<asp:LinkButton id="hypNext" runat="server">Next</asp:LinkButton></P>
<P> </P>
<P>
<asp:Literal id="myPage" runat="server"></asp:Literal></P>
<P> </P>
</form>
</body>
</HTML>
Default.aspx.vb:
Code:
Imports System.Net
Imports System.IO
Public Class _Default
Inherits System.Web.UI.Page
Protected WithEvents hypPrevious As System.Web.UI.WebControls.LinkButton
Protected WithEvents hypNext As System.Web.UI.WebControls.LinkButton
Protected WithEvents lblPageNo As System.Web.UI.WebControls.Label
Protected WithEvents myPage As System.Web.UI.WebControls.Literal
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblPageNo.Text = Session("PageNo")
Dim storefile As Directory
Dim directory As String
Dim files As String()
Dim File As String
Dim i As Integer
files = storefile.GetFiles("e:\inetpub\ori.net\mandreko\highschoolsports1\", "page*.html")
For i = 0 To (files.Length - 1)
files(i) = files(i).Replace("e:\inetpub\ori.net\mandreko\highschoolsports1\", "")
Next
Select Case Session("PageNo")
Case 1
hypPrevious.Visible = False
hypNext.Visible = True
Case files.Length
hypPrevious.Visible = True
hypNext.Visible = False
Case Else
hypPrevious.Visible = True
hypNext.Visible = True
End Select
'DataGrid1.DataSource = files
'DataGrid1.DataBind()
myPage.Text = readHtmlPage("http://www.ori.net/mandreko/highschoolsports1/page" & Session("PageNo") & ".html")
myPage.DataBind()
End Sub
Function readHtmlPage(ByVal url As String) As String
Dim objResponse As WebResponse
Dim objRequest As WebRequest
Dim result As String
objRequest = System.Net.HttpWebRequest.Create(url)
objResponse = objRequest.GetResponse()
Dim sr As New StreamReader(objResponse.GetResponseStream())
result = sr.ReadToEnd()
'clean up StreamReader
sr.Close()
Return result
End Function
Private Sub hypPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hypPrevious.Click
Session("PageNo") = Session("PageNo") - 1
myPage.DataBind()
End Sub
Private Sub hypNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hypNext.Click
Session("PageNo") = Session("PageNo") + 1
myPage.DataBind()
End Sub
End Class