Beginner's question - How do you redirect a user to another page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RobG

    Beginner's question - How do you redirect a user to another page

    Hi there,

    I have a form and when the user clicks the submit button, I want the handler
    for that on the server side to redirect ("post") the form to a URL at
    another site (not my own). It should appear to the user's browser as if the
    form's "action" attribute were set to that site to begin with (so the start
    page at that site will have access to the hidden fields on the form - it's
    expecting them). Thanks in advance.


  • Mark Rae [MVP]

    #2
    Re: Beginner's question - How do you redirect a user to another page

    "RobG" <no_spam@_nospa m.comwrote in message
    news:ebI9rDIeIH A.6092@TK2MSFTN GP06.phx.gbl...
    I have a form and when the user clicks the submit button, I want the
    handler for that on the server side to redirect ("post") the form to a URL
    at another site (not my own). It should appear to the user's browser as if
    the form's "action" attribute were set to that site to begin with (so the
    start page at that site will have access to the hidden fields on the
    form - it's expecting them).
    The simplest way would be to use an HTML form instead of an ASP.NET form
    e.g.

    <form method="post" action="http://www.theotherweb site.com">

    </form>

    Of course, that will mean that you can't use any webcontrols at all but,
    since you're not posting back, I'm guessing that probably won't matter too
    much...


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • RobG

      #3
      Re: Beginner's question - How do you redirect a user to another page

      >I have a form and when the user clicks the submit button, I want the
      >handler for that on the server side to redirect ("post") the form to a
      >URL at another site (not my own). It should appear to the user's browser
      >as if the form's "action" attribute were set to that site to begin with
      >(so the start page at that site will have access to the hidden fields on
      >the form - it's expecting them).
      >
      The simplest way would be to use an HTML form instead of an ASP.NET form
      e.g.
      >
      <form method="post" action="http://www.theotherweb site.com">
      >
      </form>
      >
      Of course, that will mean that you can't use any webcontrols at all but,
      since you're not posting back, I'm guessing that probably won't matter too
      much...
      Thanks for the feedback. Unfortunately, I need the submit button handler to
      set a hidden field based on the value of one of the form's controls (ideally
      I'd like to dynamically create his hidden field on-the-fly - not sure how
      though). Once set, it can then post to the real the URL but again, it should
      appear as if the user went directly there to begin with. Do you know how to
      pull this off? Thanks again.


      Comment

      • RobG

        #4
        Re: Beginner's question - How do you redirect a user to another page

        ... dynamically create his hidden field ...

        s/this/his


        Comment

        • Mark Rae [MVP]

          #5
          Re: Beginner's question - How do you redirect a user to another page

          "RobG" <no_spam@_nospa m.comwrote in message
          news:%23u8s2VIe IHA.4464@TK2MSF TNGP02.phx.gbl. ..
          Thanks for the feedback. Unfortunately, I need the submit button handler
          to set a hidden field based on the value of one of the form's controls
          Is there a reason that can't you use JavaScript for that...?


          --
          Mark Rae
          ASP.NET MVP


          Comment

          • RobG

            #6
            Re: Beginner's question - How do you redirect a user to another page

            Hmm - OK...
            >
            In which case, I can only think of the following:
            >
            1) Keep your existing page which does the postback to encrypt the data
            >
            2) Add an <asp:Literalcon trol to the page
            >
            3) As part of the postback, use a StringBuilder to create the entire text
            of an HTML form and add that to the Literal control
            >
            4) Finally, inject a piece of JavaScript to submit the dynamically created
            form
            >
            This is pretty messy, but it's not unheard of... E.g. this is the way
            people typically integrate PayPal into their ASP.NET apps...
            Thanks very much. I'll be looking into this immediately. Note that I also
            just came across the following which looks promising:

            This article shows you how to post a Form data to a different URL from ASP.NET pages. For example, you might need to send user to a third party payment processing system using post method. ASP.NET does not provide any straight forward way to accomplish this task.


            I have yet to look at it in detail but the author states (as you yourself do
            indirectly) that ASP.NET provides no clean way to do this. That comes as a
            surprise to me but so long as it can be done somehow (even using unwieldy
            techniques) I'm grateful. Thanks again.


            Comment

            • RobG

              #7
              Re: Beginner's question - How do you redirect a user to another page

              This is the updated link on the author's site:




              Comment

              • Mark Rae [MVP]

                #8
                Re: Beginner's question - How do you redirect a user to another page

                "RobG" <no_spam@_nospa m.comwrote in message
                news:exVLTyIeIH A.5280@TK2MSFTN GP02.phx.gbl...
                This is the updated link on the author's site:
                >
                http://www.jigar.net/articles/viewhtmlcontent78.aspx
                That's pretty much what I was suggesting, though I think the author is
                perhaps being a little too clever for his own good...

                Specifically, I try to avoid writing directly to the Response stream because
                you can't always guarantee where things go... Having said that, the first
                thing that the author's code does is to clear the Response stream, so this
                is probably OK...


                --
                Mark Rae
                ASP.NET MVP


                Comment

                • Cowboy \(Gregory A. Beamer\)

                  #9
                  Re: Beginner's question - How do you redirect a user to another page

                  You can set the form tag to point anywhere you like, as Mark has pointed
                  out.

                  One potential issue, however, is the browser may alert the user of your
                  action, as you are working cross site. In addition, if the form at the other
                  side can be set up to not allow what you are attempting (you have this
                  worked out already with the guys on the other side?).

                  --
                  Gregory A. Beamer
                  MVP, MCP: +I, SE, SD, DBA

                  *************** *************** *************** ****
                  | Think outside the box!
                  |
                  *************** *************** *************** ****
                  "RobG" <no_spam@_nospa m.comwrote in message
                  news:ebI9rDIeIH A.6092@TK2MSFTN GP06.phx.gbl...
                  Hi there,
                  >
                  I have a form and when the user clicks the submit button, I want the
                  handler for that on the server side to redirect ("post") the form to a URL
                  at another site (not my own). It should appear to the user's browser as if
                  the form's "action" attribute were set to that site to begin with (so the
                  start page at that site will have access to the hidden fields on the
                  form - it's expecting them). Thanks in advance.
                  >

                  Comment

                  Working...