ASP.Net : PreviousPage issues with Content page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rjvrnjn
    New Member
    • Apr 2007
    • 26

    #1

    ASP.Net : PreviousPage issues with Content page

    I'm trying to pass a variable value from one page to another. Of all the ways that are available, I like the PreviousPage.Fi ndControl() one as it lets me access the previous page controls and get the value without me being bothered about security et al. But what I find is once the page is posted the only controls that I get in PreviousPage is the master page and none of the controls of the content page are available in PreviousPage.Co ntrols collection. I checked through Request.ServerV ariables("HTTP_ REFERER") and found that the page is correctly being referred. Does anybody has any idea if this is at all feasible or if there is some other workaround?
    Thanks.
  • balame2004
    New Member
    • Mar 2008
    • 142

    #2
    Originally posted by rjvrnjn
    I'm trying to pass a variable value from one page to another. Of all the ways that are available, I like the PreviousPage.Fi ndControl() one as it lets me access the previous page controls and get the value without me being bothered about security et al. But what I find is once the page is posted the only controls that I get in PreviousPage is the master page and none of the controls of the content page are available in PreviousPage.Co ntrols collection. I checked through Request.ServerV ariables("HTTP_ REFERER") and found that the page is correctly being referred. Does anybody has any idea if this is at all feasible or if there is some other workaround?
    Thanks.
    Hello there,

    Why don't you try Session objects. It is an easy way to maintain objects within a session so you can easily share the objects between web pages.



    - Balaji U

    Comment

    • rjvrnjn
      New Member
      • Apr 2007
      • 26

      #3
      Originally posted by balame2004
      Hello there,
      Why don't you try Session objects. It is an easy way to maintain objects within a session so you can easily share the objects between web pages.
      - Balaji U
      I think Session variables should not be used for passing variables from one form to another (as evidently we've multiple other ways of passing variables). My standpoint is to use Session variable when a particular value will be utilized across many pages. Thanks anyways for your suggestion & time.

      Anybody has faced the situation that I've at hand?

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by rjvrnjn
        I'm trying to pass a variable value from one page to another. Of all the ways that are available, I like the PreviousPage.Fi ndControl() one as it lets me access the previous page controls and get the value without me being bothered about security et al. But what I find is once the page is posted the only controls that I get in PreviousPage is the master page and none of the controls of the content page are available in PreviousPage.Co ntrols collection. I checked through Request.ServerV ariables("HTTP_ REFERER") and found that the page is correctly being referred. Does anybody has any idea if this is at all feasible or if there is some other workaround?
        Thanks.
        You should review the ASP Page Life Cycle.
        A request is made by the browser to the server, the server compiles all the code and handles the request, the data is sent back to the browser and all objects used in the request are destroyed.

        Therefore, you cannot access information on a previous page request.

        In order to use data that is persistent on every page you have to either send this data to the server upon every request (via cookies, through the URL etc) or you save that information on the server in Session.

        Another interesting way of passing information between web pages is through using Server.Transfer instead of Request.Redirec t....eg say you have a LinkButton on the page that loads a new page, in the LinkButton's OnClick event (server side) youwould use Server.Transfer to direct the user to the new page...when using Server.Transfer all variables on the previous page request become available to the page that the user is is transfered to. There are some peculiarities to using Server.Transfer (the URL in the browser does change so the user can't book mark etc etc) so you should do research into this before deciding to go with this idea.

        I myself prefer using Session to store my persistent data for the user.

        -Frinny

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Originally posted by rjvrnjn
          I think Session variables should not be used for passing variables from one form to another (as evidently we've multiple other ways of passing variables). My standpoint is to use Session variable when a particular value will be utilized across many pages. Thanks anyways for your suggestion & time.

          Anybody has faced the situation that I've at hand?
          Wait a sec, you're just passing between Froms?
          Why not using a hidden field?

          I'm not sure but even ViewState might be possible....

          -Frinny

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by rjvrnjn
            I'm trying to pass a variable value from one page to another...
            Oh no, you said One page to Another Page.

            In this case hidden fields and ViewState wont help you.
            I still think that Session will be easier for you.

            -Frinny

            Comment

            • rjvrnjn
              New Member
              • Apr 2007
              • 26

              #7
              Thanks guys for the replies. I think I'll go with Session variable.
              @Frinny, thanks for the detailed explanation but you said:
              ...Therefore, you cannot access information on a previous page request....
              But MSDN says :
              If the source and target pages are both ASP.NET Web pages and in the same Web application, you can read the values of controls on the source page while in the target page. You might use this strategy if the source page does not expose public properties containing the information you need.
              This leads me to think that this is possible. Is there something else implied and I am missing it?

              Server.Transfer indeed looked great initially, but found that it doesn't give the correct URL and hence is not useful to me.

              Comment

              • rjvrnjn
                New Member
                • Apr 2007
                • 26

                #8
                Originally posted by Frinavale
                Oh no, you said One page to Another Page.
                In this case hidden fields and ViewState wont help you.
                I still think that Session will be easier for you.
                -Frinny
                On the risk of sounding very naive, what is this different between Form & Page?

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #9
                  Originally posted by rjvrnjn
                  On the risk of sounding very naive, what is this different between Form & Page?
                  Most of the time when you're making ASP.NET applications you just use the the ASPX pages as is. They are automatically generated for you and include one <form> tag. You can have more than one form tag on an ASPX page.


                  MSDN says :
                  If the source and target pages are both ASP.NET Web pages and in the same Web application, you can read the values of controls on the source page while in the target page. You might use this strategy if the source page does not expose public properties containing the information you need.
                  This pertains to using the Server.Transfer method only. Recall I was saying that using this method of transferring between pages, all the variables on the original page request become available to the page that the user is is transfered to.....


                  -Frinny

                  Comment

                  • rjvrnjn
                    New Member
                    • Apr 2007
                    • 26

                    #10
                    Originally posted by Frinavale
                    Most of the time when you're making ASP.NET applications you just use the the ASPX pages as is. They are automatically generated for you and include one <form> tag. You can have more than one form tag on an ASPX page.
                    I understand it better now. :)
                    Originally posted by Frinavale
                    MSDN says :
                    This pertains to using the Server.Transfer method only. Recall I was saying that using this method of transferring between pages, all the variables on the original page request become available to the page that the user is is transfered to.....
                    Hmm... they didn't mention that explicitly and hence had me wondering if it applies to any kind of redirection.
                    Thanks for the effort you took to explain. Thanks very much.

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      Originally posted by Frinavale
                      This pertains to using the Server.Transfer method only. Recall I was saying that using this method of transferring between pages, all the variables on the original page request become available to the page that the user is is transfered to.....
                      Actually it appears that there are 2 ways to pass all the variables....bu t you have to use Cross-Page Posting. I've never done this myself and so I didn't even think about it until I continued reading that article you posted.

                      The interesting thing is that the Cross-Page Posting is only set up for specific controls (those that implement the IButtonControl interface)....s o basically you can have a button that calls another ASPX page to do processing. In this case, in the ASPX page that the button calls to do this processing the Page.PreviousPa ge property contains the information that you're looking for.

                      Were you trying to use Cross-Page Posting??


                      You learn something new every day :D
                      Thanks for this article.

                      -Frinny

                      Comment

                      Working...