Click here to Skip to main content
15,911,317 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello sirs, first of all let me say that I am a newbie in this programming language. Now sirs here is my problem. ive connected to pages with session in it. Now when im on the second page and done with my first choice I'll return to the first page [using backspace] and choose another one. All went well but when I choose to go back on my first choice it stuck up on my last choice. plss help dont know what the problem is
My code on first page:
VB
Partial Class UpdateTP
    Inherits System.Web.UI.Page



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        End Sub
    Protected Sub a2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles a2.Click
        Session("CC15029") = a2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub b2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles b2.Click
        Session("CC12934") = b2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub c2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles c2.Click
        Session("CC12935") = c2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub d2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles d2.Click
        Session("CC12938") = d2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub y2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles y2.Click
        Session("CC12939") = y2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub f2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles f2.Click
        Session("CC12940") = f2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub g2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles g2.Click
        Session("CC12941") = g2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub h2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles h2.Click
        Session("CC12942") = h2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub i2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles i2.Click
        Session("CC12943") = i2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub j2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles j2.Click
        Session("CC12944") = j2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub k2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles k2.Click
        Session("CC12948") = k2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub l2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles l2.Click
        Session("CC12950") = l2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub m2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles m2.Click
        Session("CC12952") = m2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub n2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles n2.Click
        Session("CC13082") = n2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub o2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles o2.Click
        Session("CC13154") = o2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub p2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles p2.Click
        Session("CC13241") = p2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub q2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles q2.Click
        Session("CC13242") = q2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub r2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles r2.Click
        Session("CC13244") = r2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub s2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles s2.Click
        Session("CC13245") = s2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub t2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles t2.Click
        Session("CC14699") = t2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub u2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles u2.Click
        Session("CC16121") = u2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub v2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles v2.Click
        Session("CC16339") = v2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub w2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles w2.Click
        Session("CC16565") = w2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub

    Protected Sub x2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles x2.Click
        Session("CC16646") = x2.Text
        Response.Redirect("TrainingPlanM.aspx")
    End Sub
End Class


My Code on Second Page:
VB
Public Sub sesyon()
        Dim cc15029 As String = Session("cc15029")
        Dim cc12934 As String = Session("cc12934")
        Dim cc12935 As String = Session("cc12935")
        Dim cc12938 As String = Session("cc12938")
        Dim cc12939 As String = Session("cc12939")
        Dim cc12940 As String = Session("cc12940")
        Dim cc12941 As String = Session("cc12941")
        Dim cc12942 As String = Session("cc12942")
        Dim cc12943 As String = Session("cc12943")
        Dim cc12944 As String = Session("cc12944")
        Dim cc12948 As String = Session("cc12948")
        Dim cc12950 As String = Session("cc12950")
        Dim cc12952 As String = Session("cc12952")
        Dim cc13082 As String = Session("cc13082")
        Dim cc13154 As String = Session("cc13154")
        Dim cc13241 As String = Session("cc13241")
        Dim cc13242 As String = Session("cc13242")
        Dim cc13244 As String = Session("cc13244")
        Dim cc13245 As String = Session("cc13245")
        Dim cc14699 As String = Session("cc14699")
        Dim cc16121 As String = Session("cc16121")
        Dim cc16339 As String = Session("cc16339")
        Dim cc16565 As String = Session("cc16565")
        Dim cc16646 As String = Session("cc16646")

        If Not cc15029 = "" Then
            lblcc.Text = cc15029
        End If
        If Not cc12934 = "" Then
            lblcc.Text = cc12934
        End If
        If Not cc12935 = "" Then
            lblcc.Text = cc12935
        End If
        If Not cc12938 = "" Then
            lblcc.Text = cc12938
        End If
        If Not cc12939 = "" Then
            lblcc.Text = cc12939
        End If
        If Not cc12940 = "" Then
            lblcc.Text = cc12940
        End If
        If Not cc12941 = "" Then
            lblcc.Text = cc12941
        End If
        If Not cc12942 = "" Then
            lblcc.Text = cc12942
        End If
        If Not cc12943 = "" Then
            lblcc.Text = cc12943
        End If
        If Not cc12944 = "" Then
            lblcc.Text = cc12944
        End If
        If Not cc12948 = "" Then
            lblcc.Text = cc12948
        End If
        If Not cc12950 = "" Then
            lblcc.Text = cc12950
        End If
        If Not cc12952 = "" Then
            lblcc.Text = cc12952
        End If
        If Not cc13082 = "" Then
            lblcc.Text = cc13082
        End If
        If Not cc13154 = "" Then
            lblcc.Text = cc13154
        End If
        If Not cc13241 = "" Then
            lblcc.Text = cc13241
        End If
        If Not cc13242 = "" Then
            lblcc.Text = cc13242
        End If
        If Not cc13244 = "" Then
            lblcc.Text = cc13244
        End If
        If Not cc13245 = "" Then
            lblcc.Text = cc13245
        End If
        If Not cc14699 = "" Then
            lblcc.Text = cc14699
        End If
        If Not cc16121 = "" Then
            lblcc.Text = cc16121
        End If
        If Not cc16339 = "" Then
            lblcc.Text = cc16339
        End If
        If Not cc16565 = "" Then
            lblcc.Text = cc16565
        End If
        If Not cc16646 = "" Then
            lblcc.Text = cc16646
        End If
    End Sub
Posted
Updated 13-Jul-11 18:36pm
v2

All of this is disasterous. Why not tell us what you're trying to do here, so we can tell you how to not do it badly ? You should not rely on hitting 'backspace' to go back to the previous page. You can code a link to the previous page, but it will reload the page, and there is no guarentee it will do it with things selected as they were. It's better to pass a URL you can use to put a value on the query string to browse to. Or, if users are going to toggle a lot, make both pages controls and put them on the one page so you can use viewstate to store values.
 
Share this answer
 
Comments
drkterror 14-Jul-11 0:25am    
sir im trying to do is that it may vary on what the user click. it is not finished yet sir . Here is the continue (sorry sir if i cos you a lot of trouble trying to learn ASP.net because in our school it is not teaching)
Public Sub BindData()
Dim strSQL As String
'Dim a As Integer
Dim connection As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
strSQL = "SELECT * FROM [TblDUMMY] WHERE ([CourseCode] = @CourseCode)"
connection.Open()
Dim command As New SqlCommand(strSQL, connection)
command.Parameters.AddWithValue("@CostCenter", lblcc.Text)
Dim DataReader As SqlClient.SqlDataReader = command.ExecuteReader()
Do While DataReader.Read()
lblID.Text = (DataReader("ID").ToString)
Christian Graus 14-Jul-11 0:31am    
I'm sorry, I don't see any correlation between the two code snippets you posted, and I have still no idea what you want to do.
drkterror 14-Jul-11 0:36am    
Uhmm. let me rephrase.. um.. heres what i do ive put a link button and name in as a2...x2 and their text is a number which correspond to a column in my database
now what i do is i use session(dont know if i do it right) and their text that it will be sent to the next page where the text of lblcc.text will be the session of what i clicked. Then goes to the connection using lblcc as parameters
No, this is not how a program of any kind can be written. Programming is all about abstraction and DRY principle (Don't Repeat Yourself, see http://en.wikipedia.org/wiki/Don%27t_repeat_yourself[^]).

There are many very similar code lines of fragments repeated almost as many times as the number of letters in English alphabet (I have not idea, why not all of the letters). Each of these fragments should not be repeated; it should be presented zero times or only one time. Ever heard of parameters of method? of loops?

No immediate constants should be used, especially of string type, such as "a", "b"… Even "" should be written as string.Empty.

Methods should really short, each having clear semantic name suggestive of its purpose; naming conventions should be observed.

Those are elementary criteria. Until this is done, any programming activity makes no sense at all. It's much better not to write anything (use this time for reading on language and programming), then to write this way. Any discussion of exceptions makes no sense as well.

—SA
 
Share this answer
 
Comments
drkterror 14-Jul-11 0:29am    
sir so you are suggesting looping and that im gonna use array?
Sergey Alexandrovich Kryukov 14-Jul-11 1:23am    
How can you do without loops? Arrays -- maybe, there are other containers...
--SA
arathi_suresh 14-Jul-11 0:49am    
well said SAKryukov. My +5.
Sergey Alexandrovich Kryukov 14-Jul-11 1:24am    
Thank you.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900