Passing Form Data

Discussion in 'ASP .Net' started by Mike, Dec 3, 2004.

  1. Mike

    Mike Guest

    I'm moving to ASP.NET and was wondering what is the best way to pass
    form data from one aspx page to another?

    Mike
     
    Mike, Dec 3, 2004
    #1
    1. Advertising

  2. Like all things computer science related, "best" is a relative term and
    depends on your needs.

    Here are your options:
    1) Querystring
    2) Session variables
    3) Application variables
    4) Static variables.
    5) Cookies
    6) (and probably others)

    I, myself, try to stay away from things that persist on the server like
    static variables because they can sometimes be difficult to troubleshoot a
    site since they can be set by any pieces of code. I usually like
    querystrings because they can get set by the user manually which might help
    in debugging as you can jump to a scinerio immeidatly. But this all depends
    on your needs.

    "Mike" <> wrote in message
    news:#...
    > I'm moving to ASP.NET and was wondering what is the best way to pass
    > form data from one aspx page to another?
    >
    > Mike
     
    Peter Rilling, Dec 3, 2004
    #2
    1. Advertising

  3. What's the best way to get from Chicago to New York? Answer: It all depends
    on requirements and circumstances.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Neither a follower
    nor a lender be.

    "Mike" <> wrote in message
    news:#...
    > I'm moving to ASP.NET and was wondering what is the best way to pass
    > form data from one aspx page to another?
    >
    > Mike
     
    Kevin Spencer, Dec 3, 2004
    #3
  4. Mike

    Scott M. Guest

    What you may not be aware of is that in .NET, we use a one-page form
    paradigm. That is that in .NET, form data is submitted to the same page.
    So, the need to move form data from one page to another is no really needed.

    The first time a page loads (before the user has had a chance to submit
    anything) is referred to as "not a postback". A page that is loading for
    the 2nd or 200th time because form data was submitted is called a
    "postback". When a page is loading up, you'll want to know if the page is
    loading because form data was submitted (and therefore, you want to access
    that data and use it) or is the page loading for the first time (or because
    of a refresh). We can use this code (VB.NET) to check:

    Sub Page_Load
    If Not IsPostBack Then
    'Page is loading for either the first time or as the result of a
    refresh

    Else
    'Page is loading as a result of the form data being submitted
    'Access the form data directly via the control names you used to
    create the form

    End If
    End Sub

    Of course, if you need to use that form data on subsequent pages, you can
    still use classic ASP mechanisms to do it (QueryStrings, Hidden Form Fields,
    Server.Transfer, etc.) and you can use new .NET mechanisms as well (adding
    data to the cache, global shared variables, custom objects, etc.).


    "Mike" <> wrote in message
    news:%...
    > I'm moving to ASP.NET and was wondering what is the best way to pass form
    > data from one aspx page to another?
    >
    > Mike
     
    Scott M., Dec 3, 2004
    #4
  5. Mike

    Amstaff Guest

    Personally I prefer the ValueHolder designe pattern.
    Create a class that has properties for all the form values
    you need to keep. In the code behind of the submitting
    aspx create the the valueholder set all the values and the
    pass it along either on the request or into a service
    layer.
    >-----Original Message-----
    >Like all things computer science related, "best" is a

    relative term and
    >depends on your needs.
    >
    >Here are your options:
    > 1) Querystring
    > 2) Session variables
    > 3) Application variables
    > 4) Static variables.
    > 5) Cookies
    > 6) (and probably others)
    >
    >I, myself, try to stay away from things that persist on

    the server like
    >static variables because they can sometimes be difficult

    to troubleshoot a
    >site since they can be set by any pieces of code. I

    usually like
    >querystrings because they can get set by the user

    manually which might help
    >in debugging as you can jump to a scinerio immeidatly.

    But this all depends
    >on your needs.
    >
    >"Mike" <> wrote in

    message
    >news:#...
    >> I'm moving to ASP.NET and was wondering what is the

    best way to pass
    >> form data from one aspx page to another?
    >>
    >> Mike

    >
    >
    >.
    >
     
    Amstaff, Dec 3, 2004
    #5
  6. Here's a nice, simple way to pass values from one page to another:
    (VB.NET code)

    'Add data to the context object before transferring
    Context.Items("myParameter") = x
    Server.Transfer("WebForm2.aspx")

    Then, in WebForm2.aspx:

    'Grab data from the context property
    Dim x as Integer = CType(Context.Items("myParameter"),Integer)

    Of course there are a number of ways to pass values from one page to
    another, such as using the querystring, cookies, session,
    context, saving to a temporary table in the database between each page, etc.
    You'll have to decide which technique is best for your application.
    Here are several good articles on the subject to help you decide.
    http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/default.aspx

    http://www.aspalliance.com/kenc/passval.aspx

    http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=600

    http://www.dotnetbips.com/displayarticle.aspx?id=79

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://Steve.Orr.net


    "Mike" <> wrote in message
    news:%...
    > I'm moving to ASP.NET and was wondering what is the best way to pass form
    > data from one aspx page to another?
    >
    > Mike
     
    Steve C. Orr [MVP, MCSD], Dec 3, 2004
    #6
    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. Mart Rogers

    passing arguments from web-form to win-form

    Mart Rogers, Jul 8, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    594
    Natty Gur
    Jul 9, 2003
  2. Replies:
    5
    Views:
    778
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Jun 12, 2007
  3. Mart Rogers

    passing arguments from web-form to win-form

    Mart Rogers, Jul 8, 2003, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    144
    David Boaz
    Jul 8, 2003
  4. DanC
    Replies:
    2
    Views:
    124
  5. Kevin DeValck
    Replies:
    1
    Views:
    739
    7stud --
    May 17, 2011
Loading...

Share This Page