Thursday, July 9, 2009

How do I send a value from one ASP page to two different pages?

I have a page called welcome.asp which generates a username. From that page I am using Response.Redirect() to send it to another page called addOrder.asp. Now, what I want is to be able to access the same value from another page - say addOrder2.asp at the same time. How is it possible?

How do I send a value from one ASP page to two different pages?
Since your page has an .asp extension and not an .aspx extension, I'll assume ASP 3.0. I will also assume that addOrder.asp is on the same server as your welcome page. Here's what you do:





%26lt;%


'welcome.asp


'how does the username get generated?


Session("username") = "some username"


Response.Redirect( "addOrder.asp" )


%%26gt;


---------------------


%26lt;%


'addOrder2.asp


username = Session("username")


'if there is no username, should they log in?


If IsEmpty(username) Or Len(username) = 0 Then


Response.Redirect( "welcome.asp" )


End If


'the rest of your code goes here


%%26gt;





The ASP Session object stores the username between page requests. On the pages where you'll need the username, you will have to check to see if it exists and send the user to some sort of login page if it does not exist.
Reply:1.u can use the query string method.


2. store the data in a database and access it across pages.


3.You could use cookies
Reply:Hi ,





U Must use the Session Object for that Ur Constraints...
Reply:Use the session variable. It's the safest and hardest to change storage method. Query string is visible in the URL so people can change that. Cookies can also be changed.





Session["my_data"] = my_data





and when you need it:


if (Session["my_data"]!=null %26amp;%26amp; Session["my_data"].ToString()!="")


{


data = Session["my_data"].ToString();


}





assuming you store a string value.


If you store an integer, you can do something like;


data = Int32.Parse(Session["my_data"].ToString(...





(P.S. code written in C#)
Reply:%26lt;form action="post" type action="page1.asp", "page2.asp"...


in the page wer the form is...


No comments:

Post a Comment