images with sessions in asp
-
hi, can anyone help me on this problem thats occurring. I created a forum and its like this .. www.ivanandsimone.com/Query/Home.aspx. Now the problem is this, when i enter in the home.aspx 3 imagebuttons of 3 different items are shown above the page for instance (mobile, computer and book). When someone click on a picture it will take him in its (item description) of that item. at that point everything works well but when a person clicks the back button of the windows explorer from the taskbar .. the pictures will ramins the same (mobile, computer and book) but the sessions will be overwrited by other numbers. I am using Sessions to store every picture (the 3 pictures) ID number and then send that ID number to the Item.aspx page. The Item.aspx page will then see the ID and from the database it will search for the information about that ID that the user chosen. Now the code is this: This is for the Page_Load
If Request.QueryString("ItemID") <> "" Then Session(ID) = Request.QueryString("ItemID") Response.Redirect("Item.aspx") End If If Not IsPostBack Then Try odcConn = New OleDbConnection(strConn) daMem = New OleDbDataAdapter("Select * From tblItems Order By ItemID Desc", odcConn) dsMem.Clear() daMem.Fill(dsMem, "tblItems") dgItems.SelectedIndex = -1 dgItems.DataSource = dsMem.Tables("tblItems") dgItems.DataBind() odcConn.Close() Session("Num1") = Nothing Session("Num2") = Nothing Session("Num3") = Nothing FillCategories() Catch ex As Exception odcConn.Close() End Try End If ChooseItems() End Sub
So the sessions - Session("Num1") and the other 2 are the storeage that i told you. Now for the Image Picker of the ImageButtons I am using this code:Private Sub ChooseItems() Dim strImage As String Dim strItem As String Dim daItem As OleDbDataAdapter Dim ds As New DataSet Dim i As Integer = 0 Dim randNum As New Random Dim intNum As Integer = randNum.Next(0, 22) odcConn = New OleDbConnection(strConn) daItem = New OleDbDataAdapter("SELECT * FROM tblItems", odcConn) daItem.Fill(ds, "tblItems") Try strImage = ds.Tables("tblItems").Rows(intNum)("
-
hi, can anyone help me on this problem thats occurring. I created a forum and its like this .. www.ivanandsimone.com/Query/Home.aspx. Now the problem is this, when i enter in the home.aspx 3 imagebuttons of 3 different items are shown above the page for instance (mobile, computer and book). When someone click on a picture it will take him in its (item description) of that item. at that point everything works well but when a person clicks the back button of the windows explorer from the taskbar .. the pictures will ramins the same (mobile, computer and book) but the sessions will be overwrited by other numbers. I am using Sessions to store every picture (the 3 pictures) ID number and then send that ID number to the Item.aspx page. The Item.aspx page will then see the ID and from the database it will search for the information about that ID that the user chosen. Now the code is this: This is for the Page_Load
If Request.QueryString("ItemID") <> "" Then Session(ID) = Request.QueryString("ItemID") Response.Redirect("Item.aspx") End If If Not IsPostBack Then Try odcConn = New OleDbConnection(strConn) daMem = New OleDbDataAdapter("Select * From tblItems Order By ItemID Desc", odcConn) dsMem.Clear() daMem.Fill(dsMem, "tblItems") dgItems.SelectedIndex = -1 dgItems.DataSource = dsMem.Tables("tblItems") dgItems.DataBind() odcConn.Close() Session("Num1") = Nothing Session("Num2") = Nothing Session("Num3") = Nothing FillCategories() Catch ex As Exception odcConn.Close() End Try End If ChooseItems() End Sub
So the sessions - Session("Num1") and the other 2 are the storeage that i told you. Now for the Image Picker of the ImageButtons I am using this code:Private Sub ChooseItems() Dim strImage As String Dim strItem As String Dim daItem As OleDbDataAdapter Dim ds As New DataSet Dim i As Integer = 0 Dim randNum As New Random Dim intNum As Integer = randNum.Next(0, 22) odcConn = New OleDbConnection(strConn) daItem = New OleDbDataAdapter("SELECT * FROM tblItems", odcConn) daItem.Fill(ds, "tblItems") Try strImage = ds.Tables("tblItems").Rows(intNum)("
that is a frequent problem with the back button, every time that the user press this button the page do nothing (postback or not postback), the solution is hide the address bar and forces the users to navigate back using a server hiperlink control from the page. On the all htmls page write these head lines ... These lines forces the explorer to reload all the images from the server i Hope will be usefull for you :)
keep Learning and you never will be out of date...