form remembers previous text-field values

Discussion in 'ASP .Net' started by John Devlon, Oct 29, 2007.

  1. John Devlon

    John Devlon Guest

    Hi,

    I've got a small problem using 2 asp pages.....

    The first page has a button to go to the second page.

    On the second page, when the page is loaded, a check is excecuted to see if
    a session exists. If so, some values will be used to fill some textfields.
    When clicking on the button on the second page, the first page appeirs
    again.

    But when i change te values of the text-field on the second page and click
    on the button again to save the new values back to the session, the values
    of the previous time are used and not the new one...

    Could someone please help me ...?

    Thanx

    John
     
    John Devlon, Oct 29, 2007
    #1
    1. Advertising

  2. "John Devlon" <> wrote in message
    news:wztVi.180697$-ops.be...

    > I've got a small problem using 2 asp pages.....


    Are these ASP pages or ASP.NET pages...?

    > On the second page, when the page is loaded, a check is excecuted to see
    > if a session exists.


    A session will always exist - do you mean that a check is executed to see if
    a particular sssion variable exists...?

    > But when i change te values of the text-field on the second page and click
    > on the button again to save the new values back to the session, the values
    > of the previous time are used and not the new one...


    On the assumption that you're using ASP.NET and not ASP, are you fetching
    the values from session every time the second page loads, even if as a
    result of a postback...?

    Also, AAMOI, is there any particular reason that you're using two pages for
    this...?


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Oct 29, 2007
    #2
    1. Advertising

  3. John Devlon

    John Devlon Guest

    Dear Mark,

    Yes, I'm using asp.net... And I'm checking for a partical session
    variable...

    Every time, the second page is loaded, some information is read from the
    session variable...

    I just would like to know why the second time the page is visited and a
    button is clicked, the values of the first time is used, and not the new
    ones ...
    How can i prevent this ?

    John


    "Mark Rae [MVP]" <> schreef in bericht
    news:...
    > "John Devlon" <> wrote in message
    > news:wztVi.180697$-ops.be...
    >
    >> I've got a small problem using 2 asp pages.....

    >
    > Are these ASP pages or ASP.NET pages...?
    >
    >> On the second page, when the page is loaded, a check is excecuted to see
    >> if a session exists.

    >
    > A session will always exist - do you mean that a check is executed to see
    > if a particular sssion variable exists...?
    >
    >> But when i change te values of the text-field on the second page and
    >> click on the button again to save the new values back to the session, the
    >> values of the previous time are used and not the new one...

    >
    > On the assumption that you're using ASP.NET and not ASP, are you fetching
    > the values from session every time the second page loads, even if as a
    > result of a postback...?
    >
    > Also, AAMOI, is there any particular reason that you're using two pages
    > for this...?
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    John Devlon, Oct 29, 2007
    #3
  4. "John Devlon" <> wrote in message
    news:jauVi.180748$-ops.be...

    > Yes, I'm using ASP.NET... And I'm checking for a particalar session
    > variable...


    OK. For future reference, it really helps if you use the correct terms for
    things, otherwise people constantly have to ask you what you really mean...

    > Every time, the second page is loaded, some information is read from the
    > session variable...
    >
    > I just would like to know why the second time the page is visited and a
    > button is clicked, the values of the first time is used, and not the new
    > ones ...


    > How can I prevent this ?


    It's a little difficult to say for sure as you haven't shown any of your
    code, but I'm suspecting that you've forgotten to wrap your Page_Load code
    in an if (!IsPostBack) loop...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Oct 30, 2007
    #4
  5. John Devlon

    John Devlon Guest

    Dear Mark,

    Code on the first page:

    Protected Sub btnCheckOut_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles btnCheckOut.Click
    Response.Redirect("CheckOut.aspx")
    End Sub


    Second page:
    Partial Class CheckOut
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load
    Dim myCustomer As New Customer
    If Session("Customer") IsNot Nothing Then
    Me.txtFirstName.Text =
    Session("Customer").Firstname()
    Me.txtLastName.Text =
    Session("Customer").LastName()
    Me.txtMail.Text =
    Session("Customer").Email()
    End If
    End Sub

    Protected Sub btnShopping_Click(ByVal sender As Object, ByVal e
    As System.EventArgs) Handles btnShopping.Click
    If Session("Customer") Is Nothing And Page.IsValid Then
    Dim myNewCustomer As New Customer
    myNewCustomer.FirstName = Me.txtFirstName.Text
    myNewCustomer.LastName = Me.txtLastName.Text
    myNewCustomer.Email = Me.txtMail.Text
    Session.Add("Customer", myNewCustomer)
    Else
    Session("Customer").Firstname() =
    Me.txtFirstName.Text
    Session("Customer").LastName() =
    Me.txtLastName.Text
    Session("Customer").Email() = Me.txtMail.Text
    End If

    Response.Redirect("cart.aspx")
    End Sub
    End Class









    "Mark Rae [MVP]" <> schreef in bericht
    news:...
    > "John Devlon" <> wrote in message
    > news:jauVi.180748$-ops.be...
    >
    >> Yes, I'm using ASP.NET... And I'm checking for a particalar session
    >> variable...

    >
    > OK. For future reference, it really helps if you use the correct terms for
    > things, otherwise people constantly have to ask you what you really
    > mean...
    >
    >> Every time, the second page is loaded, some information is read from the
    >> session variable...
    >>
    >> I just would like to know why the second time the page is visited and a
    >> button is clicked, the values of the first time is used, and not the new
    >> ones ...

    >
    >> How can I prevent this ?

    >
    > It's a little difficult to say for sure as you haven't shown any of your
    > code, but I'm suspecting that you've forgotten to wrap your Page_Load code
    > in an if (!IsPostBack) loop...
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    John Devlon, Oct 30, 2007
    #5
  6. "John Devlon" <> wrote in message
    news:OuOVi.182263$-ops.be...

    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    > Dim myCustomer As New Customer
    > If Session("Customer") IsNot Nothing Then
    > Me.txtFirstName.Text =
    > Session("Customer").Firstname()
    > Me.txtLastName.Text =
    > Session("Customer").LastName()
    > Me.txtMail.Text =
    > Session("Customer").Email()
    > End If
    > End Sub


    As suspected, the problem is that you're running the code in Page_Load every
    time the page loads, even on postback, so you're overwriting all your
    changes...

    If Not IsPostBack Then
    Dim myCustomer As New Customer
    If Session("Customer") IsNot Nothing Then
    Me.txtFirstName.Text = Session("Customer").Firstname()
    Me.txtLastName.Text = Session("Customer").LastName()
    Me.txtMail.Text = Session("Customer").Email()
    End If
    End If


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Oct 30, 2007
    #6
  7. John Devlon

    John Devlon Guest

    Thanx Mark,

    It works great

    John




    "Mark Rae [MVP]" <> schreef in bericht
    news:...
    > "John Devlon" <> wrote in message
    > news:OuOVi.182263$-ops.be...
    >
    >> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Me.Load
    >> Dim myCustomer As New Customer
    >> If Session("Customer") IsNot Nothing Then
    >> Me.txtFirstName.Text =
    >> Session("Customer").Firstname()
    >> Me.txtLastName.Text =
    >> Session("Customer").LastName()
    >> Me.txtMail.Text =
    >> Session("Customer").Email()
    >> End If
    >> End Sub

    >
    > As suspected, the problem is that you're running the code in Page_Load
    > every time the page loads, even on postback, so you're overwriting all
    > your changes...
    >
    > If Not IsPostBack Then
    > Dim myCustomer As New Customer
    > If Session("Customer") IsNot Nothing Then
    > Me.txtFirstName.Text = Session("Customer").Firstname()
    > Me.txtLastName.Text = Session("Customer").LastName()
    > Me.txtMail.Text = Session("Customer").Email()
    > End If
    > End If
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    John Devlon, Nov 1, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    Application remembers old code???

    =?Utf-8?B?VGltOjouLg==?=, Jun 28, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    290
    =?Utf-8?B?VGltOjouLg==?=
    Jun 28, 2004
  2. Harlan Messinger
    Replies:
    1
    Views:
    421
    Patrice
    Mar 29, 2010
  3. John Nagle
    Replies:
    0
    Views:
    163
    John Nagle
    Apr 7, 2011
  4. Replies:
    6
    Views:
    300
  5. Brett_A
    Replies:
    8
    Views:
    190
    Bob Barrows [MVP]
    Apr 19, 2008
Loading...

Share This Page