Results 1 to 8 of 8

Thread: Variable lifetimes in aspx forms

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    North Yorkshire
    Posts
    102

    Variable lifetimes in aspx forms

    Hi,
    I've got a form and I want to maintain some variables that are received from a query string, i.e.,

    In the public Class of the aspx.vb file of my aspx webform, I want to create a variable that has a lifetime of the form itself.

    Can that be done "in code" or do I need to write it to a hidden field on the form as you would in ASP ?

    thanks
    Andy

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    There is no such thing as 'lifetime of a form' in ASP .NET. When someone goes to your page, the asp .net engine creates HTML and sends it to their browser. If you want to save variables you can use the Session, Application, and cache objects.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    North Yorkshire
    Posts
    102
    I just wondered if there was some other ASP.NETty way that it stored variables other than how you would pass them around in ASP. As I hadn't found one, I assumed not and you've confirmed it.

    cheers
    Andy

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    You still have the same basic fundimental problem with ASP .NET as with ASP and that is stateless pages. You just do it the same way as you would have before using Session variables, querystrings, hidden forms values, etc.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    North Yorkshire
    Posts
    102
    that's fine, I just wondered that seeing as how .NET seems to do so much more stuff, whether it had some cunning way of preserving form data other than actually on the form. I guess (as you say) , the Cache object, or session object can be used (as with normal ASP).

    cheers
    Andy

  6. #6
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    If you want to have variables keeping the values on a particular page, then you can also use ViewState object.

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What about using a Module wont that work? Or is that bad form?

  8. #8
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251
    Originally posted by Edneeis
    What about using a Module wont that work? Or is that bad form?
    I'm not positive you can use modules in ASP.NET, but I could be wrong. You could store in the Global.asax file, which from my understanding kind of works like a module.
    ~Ryan





    Have I helped you? Please Rate my posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width