Fog Creek Software
Discussion Board

[ASP.NET] Forwarding POST information

Howdy all,

I have an ASP.NET page which uses a web form to collect data for a report. I want the information in the page to be submitted to another page (using HTTP POST) AFTER it has been validated on the first page. I.E., I want the original page to both provide the input boxes, do the validation, and print any errors. If it all went well, I then want the data to be forwarded on to a second page. Is there an easy way to do this?

In case you're wondering why I want to submit data to another seperate page, it's because I want to be able to submit from both the web form, and my own applications, and from other web pages, all to the same submissions page.

Thanks guys!

Wednesday, June 23, 2004

You want to use web services. Then you can get your ASP.NET app and you winforms application to submit to the same place.

Matthew Lock
Wednesday, June 23, 2004

Hi there

I don’t know how long you have been working with server side web pages Paul. I’m going to assume that you are quite new, but if you aren’t, and I sound condescending, I apologise.

I’m also assuming that you are quite far in to the development of this web application. If you are not, please let me know, I have some beliefs in how web application’s should be written, but these generally require starting from the beginning. And as you may well know, rewriting is a practice that is frowned upon some of the members of this community, as well as Joel.

As with almost every thing in computing, there are many ways to skin a cat.

1.    Use client side script to do the validation, and post to directly to submissions page.
See for a good JScript tutorial.
See for examples of client-side form validation.

Why will the posts from the application not have to validate? If it is because the application will be doing its own validation, then this is probably the best solution, as the two solutions will be similar.

2.    If the server-side validation is successful include a script to post the data to the submissions page when it has finish loading. E.g.:
function postToSubmissionPage()
<body onload = “postToSubmissionPage()”>  //only include the onload=… when validation was successful.

If you do it this way – the performance is bad because 2 http post occur, but when the Submission finally loads, the url in the browser will be correct, which is think is desirable, but I don’t have any reasons why.

This is similar to doing a Response.Redirect, except Response.Redirect will not facilitate the data transfer.

3.    Put the form data into session variables, and then do a Response.Redirect.
This is a really kak solution. Please don’t use it. It has many flaws. If you are thinking of using it, please email me and I will give you a million reasons why not to.

4.    Control the response on the server. Again, there are a number of ways to skin a cat.:
a.    Do a Server.Transfer. I have read an article on MSDN library in the past, detailing how to transfer data from the “form” page to the “submission” page. I did a search for it, but could find it. I am sure that if you look hard enough, you will probably find it. If you already have written the “form” and “submission” pages, then this is probably the best solution as it can just be “plugged” in.
b.    Create 2 panels on you page, one for the form “page”, and one for the submission “page”. The submission panel should have it’s visible property set to hidden by default. If the validation was successful, hide the form panel, and show the submission panel, by switching there visible properties. Also include a hidden field, used to indicate whether or not the form was posted for the form panel, or form the application.

Hope that this is a help. Please let me know if you want some more.

Gary van der Merwe
Wednesday, June 23, 2004

For the more sensible answer, consider encapsulating the necessary processing in a class.  Then each page that needs that behavior either derives from the class, or more likely creates an instance of that class to handle the processing.  This will be easier to implement, have better performance, and be easier to maintain than the proposed solution.

If you need additional help with this contact me via private mail and I'll be glad to help you out.  Be warned that if you actually need somebody to write the code for you, it will cost.  Hopefully though, you're a bright enough chap to figure out how to do that on your own.

Clay Dowling
Wednesday, June 23, 2004

I'm surprised nobody has mentioned that this is not only a bad idea from performance, but also from security.

If that 2nd page doesn't validate data, then I could post to it directly and bypass the validation. If it does, then what do you need the 1st page for, anyway?

Brad Wilson (
Wednesday, June 23, 2004

"I'm surprised nobody has mentioned that this is not only a bad idea from performance, but also from security."

That's because we were all waiting for the Wonder Boy Brad of .NET to come tell us to smart he is. Again.

Don't Blame Me
Wednesday, June 23, 2004

Yes, there is an easy way to do this.

Before you use it, though, consider the advice given in the rest of the posts on this topic.

That said, what you need is a method called Transfer, of the HttpServer clss. In your code, you just need to write

this.Server.Transfer(<your url>, true);

The second parameter preserves the GET/POST contents for the second page.

Raj Chaudhuri
Sunday, June 27, 2004

*  Recent Topics

*  Fog Creek Home