473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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.
Feb 26 '08 #1
8 1138
"RobG" <no_spam@_nospam.comwrote in message
news:eb**************@TK2MSFTNGP06.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.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

Feb 26 '08 #2
>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.
Feb 26 '08 #3
... dynamically create his hidden field ...

s/this/his
Feb 26 '08 #4
"RobG" <no_spam@_nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.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
http://www.markrae.net

Feb 26 '08 #5
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:Literalcontrol 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.
Feb 26 '08 #6
This is the updated link on the author's site:

http://www.jigar.net/articles/viewhtmlcontent78.aspx
Feb 26 '08 #7
"RobG" <no_spam@_nospam.comwrote in message
news:ex**************@TK2MSFTNGP02.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
http://www.markrae.net

Feb 26 '08 #8
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@_nospam.comwrote in message
news:eb**************@TK2MSFTNGP06.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.

Feb 26 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: brian_mckracken | last post by:
This might not be the right group for this question, since its kind of a pure html question... Given the html construct: <form action='index.php?expand=0,10000' method='post'> Email: <input...
11
by: suzy | last post by:
hi, i have an aspx page with a button. if i step through my code when i click the button then it calls the button_Click event which is what i want. but i need to redirect the page to another...
5
by: John W | last post by:
Hello, I have been wondering that everytime I do a submit on a button/form (postback) it is using the same webform on the CS, how do I goto another webform once I have done a postback and...
8
by: Mantorok | last post by:
Hi all When I start a new thread that tries to call: HttpContext.Current.Response.Redirect() It fails as Current returns null, is there anyway to access the current httpcontext from within...
2
by: Nathan Sokalski | last post by:
I am using the Response.Redirect method in a User Control to allow visitors to click an ImageButton to take them to another page. However, when I click the ImageButton I recieve the following...
6
by: Coleen | last post by:
Hi all :-) I need to redirect to multiple pages on click of a transmit button, without redisplaying each page. This redirection is to capture session variables that are created on each page and...
5
by: pvdg42 | last post by:
VS 2003, C# if the language matters. Scenario: Two page project, text box content on the start page is loaded into session variables to be displayed in a greeting on the second page. Works fine...
1
by: rouellette | last post by:
Is it possible to redirect to another page in your application from the start page BEFORE the user has been authenticated if you're using FORMS authentication? I can't seem to get it to work. ...
56
by: UKuser | last post by:
Hi, I'm not sure if this can be done as I've searched the web and this forum. I am using an online merchant provider and I must post certain variables to their webforms through a form on my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.