passing variables question

G

Guest

Ok, sorry if this is dumb ?, but I'm extremely new to ASP.net. I've used
PHP and am now trying to figure out the best way (or any way) to do this in
ASP.net:
I have a page where the user enters data and clicks a submit button which
redirects to another page. This 2nd page can retrieve all of the POST
variables submitted from the previous page. How is this done in ASP.net?
Thanks!
 
M

Marina

The ASP.NET model is for the first page to handle its own data submission.
It should deal with the data, and then redirect to the next page. That page
then handles all its own data.

If you did want to do what you are describing, you would either need to set
the form to post to the second page to begin with, or you would need to do a
Server.Transfer to the second page.
 
J

John

melinda said:
Ok, sorry if this is dumb ?, but I'm extremely new to ASP.net. I've used
PHP and am now trying to figure out the best way (or any way) to do this
in
ASP.net:
I have a page where the user enters data and clicks a submit button which
redirects to another page. This 2nd page can retrieve all of the POST
variables submitted from the previous page. How is this done in ASP.net?
Thanks!

ASP.NET forms by default submit to self.

I generally put my code in the button click server event. Then I redirect
to the next page if all goes well.

John
 
G

Guest

There are different technique to transfer data from one page to another. The
simple and easy way is to use Session Variable. You can also use QueryString.
For Session variable, You can save the values to a session and redirect the
destination page and then read the date from the session.

let there are two pages WebForm1.aspx and WebForm2.aspx. on the WebForm1 you
have 2 string variables and u want to access these two variables on 2nd page

U have to do on the Webform1.aspx:

string name = "Irfan";
string age = 30;

Session["anySessionVariableName1"] = name;
Session["anySessionVariableName2"] = age;

Response.Redirect("WebForm2.aspx");


on the WebForm2.aspx, u have to do for retrieving the name and age:

string nm = Session["anySessionVariableName1"].ToString();
string ag = Session["anySessionVariableName2"].ToString();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top