Page load question

  • Thread starter Thread starter Goober
  • Start date Start date
G

Goober

I have a page that receives a session variable from the default.aspx.
On Page load, the code in Page load gets executed twice. So far, no
problem. It sets the session variable each time, correctly.

However, when I click on a menu item in that page, it then executes the
same page load twice, before transferring control (via a
response.redirect) to the new page. On the first pass through the page
load of the menu page, the session variable appears to be set to
nothing, when at the end of the first page load it was set properly.


What's happening with this code? I can provide some examples if needed.

BC
 
Karl said:
Please provide some examples :)

Karl
Here you are:

Here's where it gets set in the default.aspx.vb section

sCalendar = sCalendar.Replace(":", ".")
Session("Calendar") = objReader.GetDateTime(4).ToString
Session("ViewProdHierSKUStatus") = objReader.GetString(8)
Session("ViewOldSys") = objReader.GetString(9)
Session("Permission") = objReader.GetString(10)
Response.Cookies("availabilityrptlevel").Value =
objReader.GetString(11)
---> Session("availabilityrptlevel") = objReader.GetString(11)
TransactionLog("")
Server.Transfer("sales/newmenu.aspx?User=" &
objReader.GetString(2) & "&Name=" & objReader.GetString(3) & "&Sales=" &
sSales & "&Calendar=" & sCalendar & "&P=" & objReader.GetString(6) &
"&Pass=" & objReader.GetString(1) & "&Act=" & objReader.GetString(7) &
"&SKUStat=" & Session("ViewProdHierSKUStatus") & "&Oldsys=" &
Session("ViewOldSys") & "&Permission=" & Session("Permission"))


Here is the page load piece


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Request.QueryString("User") = "" Then
lblUser.Text = Session("UserName")
End If

If Session("Sales") = "" Then
Session("Permission") = Request.QueryString("P")
Session("Pass") = Request.QueryString("Pass")
Session("UserName") = Request.QueryString("Name")
Session("ActUser") = Request.QueryString("Act")
Session("User") = Request.QueryString("User")
Session("Sales") = Request.QueryString("Sales")
Session("Calendar") = Request.QueryString("Calendar")
Session("Sales") = Session("Sales").replace("-", "/")
Session("Sales") = Session("Sales").replace(".", ":")
Session("Calendar") = Session("Calendar").replace("-", "/")
Session("Calendar") = Session("Calendar").replace(".", ":")
Session("ViewProdHierSKUStatus") =
Request.QueryString("SKUStat")
Session("ViewOldSys") = Request.QueryString("Oldsys")
End If

If Session("UserName") = "" Then
Server.Transfer("../Default.aspx")
End If
Session("ActUser") = UCase(Session("ActUser"))

Dim xxyz As String
--> xxyz = Session("availabilityrptlevel")

the above setting it equal to a string is just some test code I put in
to make sure it was getting set in this code, and was picking up the
right info in it.


When it get set = to "04" in the first part of the code (at the
objreader.getstring), it is set, and then gets passed into newmenu.aspx.

When it hits newmenu.aspx, it runs thru this code twice (below the xxyz
is just some stuff it does with which menu items show up for which
users). When the page loads, it is still set to "04". However, when I
click on the menu item, it hits page load again, and it sets the session
variable = to nothing.
 
the most common cause for this is you actually assign the onload handler
twice, look in oninit section.
 
bruce said:
the most common cause for this is you actually assign the onload handler
twice, look in oninit section.


This is the code that is immediately prior to the page load. Do not see
where I'm calling it twice.

#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
 
Make sure you aren't hookup up the event in InitializeComponent() as well as
setting AutoEventWireup to true in the aspx @Page directive.

Karl
 
If the page you have described is set as the "default document" in IIS for
this folder, there can be another reason for the double loading of the page:

if you have on the page somthing like <img src=''>, than IE thinks that the
source of the image is the current path, which is your current directory.
IIS will translate this and will think the browser asked for the default
document - which is your page !!!

See the following link for more detailed explanation
http://spaces.msn.com/members/jon-spcae/Blog/cns!1p4an4WFkHsQJSFZothKGsVA!113.entry
 
Back
Top