Variable Scope / Visibility / Caching Problem

Discussion in 'ASP .Net' started by Steve Wark, May 23, 2005.

  1. Steve Wark

    Steve Wark Guest

    If I create two aspx pages, place three text boxes (working with VS .net
    2003 and web form controls) and a button on both forms.

    On the first page, the button is set to use the "onClick" to open the second
    page using Window.Open with the values being passed to the second page by a
    global variable created in a Module added to the project, by the use of an
    Application variable and by the use of a session variable.

    In the page load of the second form the values of the text boxes are set to
    these passed values.

    When I run this as a single instance all works fine. If from another
    machine I now open this web site, while still having the first instance open
    then the data displayed on the second page reflects the first instances data
    for the global variable and the application variable, the session variables
    data is blank. If I right click and perform a refresh the data become
    correct.

    I assume this must be something to do with caching.

    Can anyone advise?

    Steve Wark


    First Pages Page_Load & Button Click
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    Response.Expires = -1

    Button1.Attributes.Add("onClick",
    "window.open('webform2.aspx','Title','width=950,height=610,left=100,top=100')")

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.Click

    v1 = TextBox1.Text

    Application("v2") = TextBox2.Text

    Session("v3") = TextBox3.Text

    End Sub


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

    Response.Expires = -1

    Button1.Attributes.Add("onClick", "window.close()")

    TextBox1.Text = v1

    TextBox2.Text = Application("v2")

    TextBox3.Text = Session("v3")

    End Sub
     
    Steve Wark, May 23, 2005
    #1
    1. Advertising

  2. Steve Wark

    Brock Allen Guest

    This approach won't work in a multi-user scenario. The variables you put
    into the module are in fact global for all users of your ASP.NET web application.
    You should look into using something like Session state to maintain per-user
    data. Here's a list of state management options (including Session):

    http://msdn.microsoft.com/library/d...e/html/cpconaspstatemanagement.asp?frame=true

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > If I create two aspx pages, place three text boxes (working with VS
    > .net 2003 and web form controls) and a button on both forms.
    >
    > On the first page, the button is set to use the "onClick" to open the
    > second page using Window.Open with the values being passed to the
    > second page by a global variable created in a Module added to the
    > project, by the use of an Application variable and by the use of a
    > session variable.
    >
    > In the page load of the second form the values of the text boxes are
    > set to these passed values.
    >
    > When I run this as a single instance all works fine. If from another
    > machine I now open this web site, while still having the first
    > instance open then the data displayed on the second page reflects the
    > first instances data for the global variable and the application
    > variable, the session variables data is blank. If I right click and
    > perform a refresh the data become correct.
    >
    > I assume this must be something to do with caching.
    >
    > Can anyone advise?
    >
    > Steve Wark
    >
    > First Pages Page_Load & Button Click
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > Response.Expires = -1
    >
    > Button1.Attributes.Add("onClick",
    > "window.open('webform2.aspx','Title','width=950,height=610,left=100,to
    > p=100')")
    > End Sub
    >
    > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    >
    > v1 = TextBox1.Text
    >
    > Application("v2") = TextBox2.Text
    >
    > Session("v3") = TextBox3.Text
    >
    > End Sub
    >
    > Second Pages Page_Load
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > Response.Expires = -1
    >
    > Button1.Attributes.Add("onClick", "window.close()")
    >
    > TextBox1.Text = v1
    >
    > TextBox2.Text = Application("v2")
    >
    > TextBox3.Text = Session("v3")
    >
    > End Sub
    >
     
    Brock Allen, May 23, 2005
    #2
    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. Steve Wark

    Variable Scope / Visibility

    Steve Wark, May 23, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    479
    Steve Wark
    May 23, 2005
  2. TTroy

    Is "scope" different from "visibility" ?

    TTroy, Feb 10, 2005, in forum: C Programming
    Replies:
    8
    Views:
    332
    Dave Thompson
    Feb 14, 2005
  3. Kaba

    Scope visibility

    Kaba, Mar 13, 2006, in forum: C++
    Replies:
    3
    Views:
    365
    Greg Comeau
    Mar 14, 2006
  4. David Filmer
    Replies:
    19
    Views:
    281
    Kevin Collins
    May 21, 2004
  5. Andrew Falanga
    Replies:
    2
    Views:
    217
    Andrew Falanga
    Nov 22, 2008
Loading...

Share This Page