Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send server side variable to new asp page 1

Status
Not open for further replies.

nogscript

Programmer
Sep 30, 2004
3
AU
Hi
I have posted this in the vbscript forum as well, so sorry if you've seen this before.

I have built an html string on an asp page based on user input from the previous page which I want to send to another page from which it will be emailed. Can someone please help me how to do this...basically the code goes:

<%Dim htmlMess
'htmlMess is built based on user input from previous page
htmlMess = "...."
...
...
...
...
htmlMess = htmlMess & "..."
%>

I then want to send the variable htmlMess to a new page when the user clicks a button, but I cannot figure out how to access htmlMess from the next page. Is there a way to reference variables between pages? and if not how should I go about accessing the html string that I require?

Thanks
 
If the new page is accessed via a form then you simply need to add a hidden variable to your form with the data, a la
Code:
<input type="hidden" name="myHTMLmess" value="<%=htmlmess%>">
On the next page you'd access the information like this
Code:
<%
Dim htmlmess

htmlmess = Request.Form("myHTMLmess")
%>
 
If they're accessing it via a click on a link then you'd embed it in the query string, though it's very important to note that the total url length cannot exceed 2054 characters, so if your "mess" is too big then you can't use this system. You'd do something like this:
Code:
<a href="newpage.asp?myHTMLmess=<%=htmlmess%>">My Link</a>
and you'd access it on the next page via
Code:
<%
Dim htmlmess

htmlmess = Request.Querystring("myHTMLmess")
%>
Another problem with that method is that if your string contains URL characters (like ? and &) then you have to encode them. The quickest way is to use Server.URLEncode, a la
Code:
htmlmess = Server.URLEncode(htmlmess)
before your link is written out.

To add insult to injury, though, encoding the characters can make them quite a bit longer. A space, for example, because "%20". As such you're even more likely to run into the maximum character limit.

The querystring is only good for reasonably short stuff, basically. If you've got a lot of info to pass from page to page then you either need to do it in a form, store it in the user's cookie (though be careful with limits there, too), or store it somewhere on the server, like in the user's Session variable or in a database.
 
Man, gotta proofread my stuff.

"because" = "becomes"

"Session variable" = "Session object
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top