Solved

"Redirect" with form POST data possible?

Posted on 2004-08-25
15
25,484 Views
Last Modified: 2011-08-18
I'm not sure if this is possible...

Situation:

I have a FORM with POST data that I'm passing on to an ASPX script for further processing.  I'd like to have the following sequence:

FormPage.htm --- POST--->WorkerPage.aspx --- "redirect" ---> DisplayInfo.aspx

The user inputs some data in the FormPage and presses submit.  This posts data to the WorkerPage where some aspx processing takes place and some data is stored in the DB (or whatever) from SOME of the form data.  Then it needs to automatically go to the DisplayInfo page where some stuff is displayed to the user for print or whatever.

The problem is the "redirect".  I can get to the DisplayInfo page but none of the POST data from the form exists any longer.  I don't know how to automatically fall into DisplayInfo from WorkerPage without a Redirect() call.

If I'm running down a rathole, please feel free to offer alternate suggestions.  I want to do it this way (rather than in the FormPage) since there are multiple "FormPages" feeding into the WorkerPage.  All need the same processing but I don't want multiple copies of the processing code in each of the FormPages.

TIA
0
Comment
Question by:jhance
  • 4
  • 3
  • 2
  • +5
15 Comments
 
LVL 2

Expert Comment

by:rlovetx
ID: 11894028
When you put your form data into the database, get the identity field of the row you inserted (using the @@identity in SQL).

Then, in your redirect to the DisplayInfo.aspx page, include the @@identity field in the url (DisplayInfo.aspx?id=623 or whatever).

On the DisplayInfo.aspx, use the id from the URL to retrieve the data you need from the database.
0
 
LVL 15

Accepted Solution

by:
Walter Ritzel earned 250 total points
ID: 11894428
If you want to pass the values received from a form to another page, three ways are possible:
- passing trhough session variables: in WorkerPage.aspx, pass the values to session variables (e.g: Session("Cod") = Request("Cod") and so on) and then call the response.redirect;

- passing through querystring, as sugested in comment above

- using HttpContext: this is the best way, I think. HttpContext is similar to session, but it exists only during the first call of the target page. Example:

HttpContext.Current.Items.Add("Cod", Request("Cod"))
Server.Transfer("DisplayInfo.aspx")

Note that I'm not using response.redirect, I'm using Server.Transfer.

Regards,

Walter.
0
 
LVL 18

Expert Comment

by:arantius
ID: 11894605
Similar to what wpcortes posted, but slightly different...
In PHP, I use code like this:

$_SESSION["oldpost"]=serialize($_POST);
header("Location: /otherpage.php");

and in otherpage.php:
$_POST=unserialize($_SESSION["oldpost"]);
unset($_SESSION["oldpost"]);


Or in short, encode the entire set of posted information into the session, do the redirect, and decode the post variables out of the session.  Unfortunately I have no idea if ASP is even capable of something like this.  If so, that should be inspiration for you though =)
0
 

Expert Comment

by:motorhead85021
ID: 11895081
In your WorkerPage, try this:

Response.Redirect "DisplayInfo.asp?value1=" & Request("value1") & "&value2=" & Request("value2") & "&value3=" & Request("value3")

That will take whatever data is sent via Post to WorkerPage, and send it along to the DisplayInfo page.

Hope this helps.


0
 

Expert Comment

by:motorhead85021
ID: 11895277
Here's a further example:

In my HTML form, I have the following fields text-boxes:
name="UserName"
name="Age"
name="City"

In the WorkerPage.aspx, when it comes time to redirect, it would look like this:

Response.Redirect "DisplayInfo.aspx?UserName=" & Request("UserName") & "&Age=" & Request("Age") & "&City=" & Request("City")

Now, the POST info sent to WorkerPage.aspx will be redirected to DisplayInfo.aspx

That example was based on ASP 3.0, but the concept is the same for ASP.NET

0
 
LVL 5

Expert Comment

by:webtrans
ID: 11896088
well all of the above solutions should work in asp.net
and also u can use data caching and then purge the cache
so mainly u have 5 solutions
1-take the variables and send them as a request variables not request.form
2-put the data in a session variable(better join them with some unique character sequence use one variable to store split in the last page and destroy the session variable)
3-save in db and either send or put in session the id
4-cache the data requested
5-save the data in an xml file on the server hard and make that file name session.sessionid.xml

:D hope this did help
0
 
LVL 32

Author Comment

by:jhance
ID: 11897975
Thanks all for your suggestions.  I'm still stuck so let me explain what I've tried and what didn't work:

1) Using the DB would be my first thought but it can't be done here.  The DB is essentially "write-only" from the web server.

2) Using "GET" parameters on the redirect URL is pretty unmanagable.  There are about 50 data items to be passed and one is quite long.  This makes for an impossibly long URL.

3) I tried the HttpContext method suggested but didn't have any success.  (BTW, the Microsoft docs on that are downright cryptic!!)  Anyway, I did:

System.Web.HttpContext.Current.Items.Add("TESTVAR", "ABCDEFG")

in my first page to create the data item.  Then I have:

Dim strTest As String
strTest = System.Web.HttpContext.Current.Items["TESTVAR"]

in my destination page.

When run in the browser I get:
 
Compiler Error Message: BC30311: Value of type 'System.Collections.IDictionary' cannot be converted to 'String'.

Line 283:<%
Line 284:      Dim strTest As String
Line 285:      strTest = System.Web.HttpContext.Current.Items["TESTVAR"]

 
So maybe this doesn't work or maybe (more likely) I'm just not understanding how to access the data in the HttpContext class.  An example might help here..

4) webtrans suggests "data caching" but I have no clue here how that applies to this situation.  If this is a serious suggestion, please elaborate.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 32

Author Comment

by:jhance
ID: 11898000
By the way, the suggestion to use:

Session("XXX") = "DATA"

etc.  does work, so unless someone has a better approach or can debunk this one as a bad idea, I'll probably accept it...
0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 11898081
To work the HttpContext solution,
just do this:

strTest = System.Web.HttpContext.Current.Items["TESTVAR"].ToString();

BTW, .ToString() works on C#, but in VB.NET must be a way to do this.

Regards,

Walter.

PS: HttpContext is probably the best solution to do this because security issues and memory issues (Session will consume more of server memory, because you must to clear the session to liberate memory, and HttpContext is managed by .NET).

0
 
LVL 32

Author Comment

by:jhance
ID: 11905351
wpcortes,

I'm not getting any success even adding the ".ToString()" to the end.  Error message is:

Object reference not set to an instance of an object.
0
 
LVL 15

Expert Comment

by:Walter Ritzel
ID: 11905414
You must use a server.transfer to change to the second page, and the Context will be available just the first time you access the second page. Any postback in the second page will erase the context.

Example:

First Page: A button will transfer to another page:
      private void btnAdd_Click(object sender, System.EventArgs e)
            {
                  HttpContext.Current.Items.Add("ScreenMode","ADD");
                  Server.Transfer("AdminAccessDellEdit.aspx");
            }

Second Page:
protected override void PageLoad(object sender, EventArgs e)
{
if (!IsPostBack)
{
string lScreenMode = HttpContext.Current.Items["ScreenMode"].ToString();
}
}

regards,
Walter.
0
 
LVL 32

Author Comment

by:jhance
ID: 11908673
wpcortes,

I was using Server.Transfer() but the error remains.  I'm baffled!  The Session() vars worked just fine so I accepted your answer.  I'll see if I can workout the HttpContext issue some other time...
0
 
LVL 6

Expert Comment

by:Fahdmurtaza
ID: 13151471
Is the same thing possible for classic asp?
Regards,
Fahd Murtaza
0
 

Expert Comment

by:comment
ID: 13342866
I've found the accepted answer is correct but I found fourth way that seems to do it faster but
it involves javascript and more coding.  
give the body of your aspx form an id like body in my case .
<body MS_POSITIONING="GridLayout" id="body">
put "protected System.Web.UI.HtmlControls.HtmlGenericControl body;" in on the .cs page above page_load fuction.
Then you can do something like
body.controls.add(new literalcontrol("<form action='someaspx.aspx' method='post' id='someform' name='someform'>)
body.controls.add(new literalcontrol(<input type=hidden id='someid' value='somevariable'>))
body.controls.add(new literalcontrol(</form>))
body.attributes.add("onload","document.getElementById('someform').submit()")
I've tried both ways and this way flies while the accepted answer was way slower.
as for fahdmurtaza question I got this idea from classic asp.
I wondering how come the servertransfer takes longer? I'd perfer the servertransfer method
(less coding)
0
 

Expert Comment

by:comment
ID: 13342922
Think i know why it take longer.
server.transfer has to go to server who then transfers to the page.
but in the above way it goes directly to the target page with the info.
jhance check to see the spelling on target page is the same.
unlike request.params[] if the param is not there it returns empty string.
HttpContext.Current.Items[] returns error if it does not find the item you are looking for.


0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Read about why website design really matters in today's demanding market.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now