This was working fine before I made some styling changes to the page.
Can you please take a look at this code and offer suggestins how to alter
it???
I added a OnInit and got a stackoverflow exception.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Me.Request.Params("Browse") Is Nothing Then
lstType = CInt(Me.Request.Params("Browse"))
Else
lstType = EnumListType.TimesheetAwaiting
Session("EmployeeID") = 1
End If
If Not IsPostBack Then
GetDocumentList()
Session("DocIndex") = 0
End If
BuildPage()
LoadDocument()
If Not IsPostBack Then
'GetDocumentList()
'Session("DocIndex") = 0
End If
End Sub
Public Sub BuildPage()
Dim tbl As New Table
Dim r As New TableRow
Dim c As TableCell
tbl.Width = Unit.Pixel(660)
tbl.Rows.Add(r)
c = New TableCell
If InStr(GetTypeDescription(lstType), "Awaiting Authorisation") Then
c.Controls.Add(New LiteralControl("<H4>" + GetTypeDescription(lstType) + "
(" + CType(Session("DocCount"), String) + ")</H4>"))
Else
c.Controls.Add(New LiteralControl("<H3>" + GetTypeDescription(lstType) + "
(" + CType(Session("DocCount"), String) + ")</H3>"))
End If
c.ColumnSpan = "2"
r.Cells.Add(c)
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Right
Dim lnk As New HyperLink
lnk.Text = "<Printable Version>"
lnk.NavigateUrl = "#"
'lnk.ForeColor = Color.Blue
lnk.Attributes("onclick") = "new_window('" &
Page.ResolveUrl("~/frmPrintDocument.aspx") & "');"
c.Controls.Add(lnk)
c.Controls.Add(New LiteralControl(" "))
c.Controls.Add(NewHyperLink("frmUserHome.aspx", "<Back to Home>", ""))
r.Cells.Add(c)
ContentArea.Controls.Add(New LiteralControl("<br><center>"))
ContentArea.Controls.Add(tbl)
ContentArea.Controls.Add(New LiteralControl("</center><br>"))
tbl = New Table
tbl.Width = Unit.Pixel(660)
r = New TableRow
tbl.Rows.Add(r)
btnPrev = New LinkButton
btnPrev.Text = "<Previous " & GetDocumentDescription(lstType) & ">"
btnPrev.ID = "btnPrev"
AddHandler btnPrev.Click, AddressOf ButtonClick
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Left
c.Controls.Add(btnPrev)
c.Width = Unit.Pixel(280)
r.Cells.Add(c)
btnNext = New LinkButton
btnNext.Text = "<Next " & GetDocumentDescription(lstType) & ">"
btnNext.ID = "btnNext"
AddHandler btnNext.Click, AddressOf ButtonClick
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Center
'_pageIndex.ForeColor = Color.DarkBlue
c.Width = Unit.Pixel(100)
c.Controls.Add(_pageIndex)
r.Cells.Add(c)
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Right
c.Controls.Add(btnNext)
c.Width = Unit.Pixel(280)
r.Cells.Add(c)
Dim objTBR As New TBRDocuments(lstType, Session("EmployeeID"),
Session("UserID"))
ContentArea.Controls.Add(New LiteralControl("<br><center>"))
ContentArea.Controls.Add(tbl)
ContentArea.Controls.Add(New LiteralControl("</center><br>"))
End Sub
Public Sub GetDocumentList()
Dim objTBR As New TBRDocuments(lstType, Session("EmployeeID"),
Session("UserID"))
Session("Documents") = objTBR
Session("DocCount") = objTBR.Count
End Sub
Public Sub LoadDocument()
Dim doc As TBRDocuments
doc = CType(Session("Documents"), TBRDocuments)
If Session("DocCount") > 0 Then
_pageIndex.Text = "(" & (Session("DocIndex") + 1).ToString & " of " &
Session("DocCount") & ")"
End If
If doc.Count > 0 Then
CallControl(doc.Documents(Session("DocIndex")))
Else
btnPrev.Visible = False
btnNext.Visible = False
End If
End Sub
Public Sub CallControl(ByVal doc As Document)
Select Case doc.DocumentType
Case enumDocType.Invoice
ctlDoc = Page.LoadControl(Page.ResolveUrl("~/Secure/ctlinvoice.ascx"))
ctlDoc.id = "ctlInvoice"
Case enumDocType.TimesheetMonthly
ctlDoc =
Page.LoadControl(Page.ResolveUrl("~/Secure/ctlTimesheetMonthly.ascx"))
ctlDoc.id = "ctlTimesheetMonthly"
Case enumDocType.TimesheetWeekly
ctlDoc =
Page.LoadControl(Page.ResolveUrl("~/Secure/ctlTimesheetWeekly.ascx"))
ctlDoc.id = "ctlTimesheetWeekly"
End Select
viewstate("docType") = doc.DocumentType
Session("PrintDoc") = doc 'So it can be printed
ctlDoc.CtlDocument = doc
ctlDoc.LoadTimesheet = True
ctlDoc.ListType = lstType
ContentArea.Controls.Add(New LiteralControl("<center>"))
ContentArea.Controls.Add(ctlDoc)
ContentArea.Controls.Add(New LiteralControl("</center>"))
SetNavControls(Session("DocIndex"), Session("DocCount"))
End Sub
Public Sub ButtonClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Select Case sender.id
Case "btnPrev"
If Session("DocIndex") > 0 Then
Session("DocIndex") -= 1
RemoveControl(ContentArea.Controls, ctlDoc.id)
LoadDocument()
End If
Case "btnNext"
If Session("DocIndex") + 1 < Session("DocCount") Then
Session("DocIndex") += 1
RemoveControl(ContentArea.Controls, ctlDoc.id)
LoadDocument()
End If
End Select
End Sub
Public Sub SetNavControls(ByVal idx As Integer, ByVal max As Integer)
If max < 2 Then
btnPrev.Visible = False
btnNext.Visible = False
ElseIf idx = 0 Then
btnPrev.Visible = False
btnNext.Visible = True
ElseIf idx < max - 1 Then
btnPrev.Visible = True
btnNext.Visible = True
Else
btnPrev.Visible = True
btnNext.Visible = False
End If
End Sub