PC Review


Reply
Thread Tools Rate Thread

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

 
 
RobG
Guest
Posts: n/a
 
      26th Feb 2008
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.


 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      26th Feb 2008
"RobG" <no_spam@_nospam.com> wrote in message
news:(E-Mail Removed)...

> 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.theotherwebsite.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
http://www.markrae.net

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      26th Feb 2008
>> 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.theotherwebsite.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.


 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      26th Feb 2008
> ... dynamically create his hidden field ...

s/this/his


 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      26th Feb 2008
"RobG" <no_spam@_nospam.com> wrote in message
news:%(E-Mail Removed)...

> 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
http://www.markrae.net

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      26th Feb 2008
>> 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...?


I need to encrypt the data on the server side and assign it to the hidden
field before posting.


 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      26th Feb 2008
"RobG" <no_spam@_nospam.com> wrote in message
news:(E-Mail Removed)...

>>> 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...?

>
> I need to encrypt the data on the server side and assign it to the hidden
> field before posting.


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:Literal> control 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...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      26th Feb 2008
> 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:Literal> control 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:

http://www.c-sharpcorner.com/UploadF...etPostURL.aspx

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.


 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      26th Feb 2008
This is the updated link on the author's site:

http://www.jigar.net/articles/viewhtmlcontent78.aspx


 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      26th Feb 2008
"RobG" <no_spam@_nospam.com> wrote in message
news:(E-Mail Removed)...

> 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
http://www.markrae.net

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner question and user ytayta555 Microsoft Access 4 10th Jul 2009 12:20 PM
redirect user to page John Microsoft ASP .NET 2 6th Jun 2006 07:27 PM
2.0: BEGINNER'S QUESTION: closing page R.A.M. Microsoft ASP .NET 5 25th May 2006 09:18 PM
Beginner Vuescan User's Question #1 David Springthorpe Scanners 6 23rd Nov 2004 07:43 AM
Redirect User to another page after some interval New ASP.NET User Microsoft ASP .NET 1 14th Jan 2004 04:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:07 AM.