magoo2
asked on
Passing Data Between Pages
Hi all,
I have a page which loads data from a database into a table. I would like to take the value of the cell clicked (date) and pass it to another page.
This is what i have so far on the code.
<% Do Until rsCustomersList.EOF%>
<tr>
<td bgcolor="f7efde" align=center>
<%= rsCustomersList("FirstName ")%>
<%= " " %>
<%= rsCustomersList("LastName" ) %>
</td>
<td bgcolor="f7efde" align=center>
<%= rsCustomersList("Username" )%>
</td>
<td bgcolor="f7efde" align=center>
<% astring = "<A HREF=bydate.asp?action=Set Date=" & rsCustomersList("Date") & " </A>" %>
<%= astring %>
<%= rsCustomersList("Date")%>
</td>
</tr>
<%
rsCustomersList.MoveNext
count = count + 1
Loop
%>
Thanks for any help
Magoo
I have a page which loads data from a database into a table. I would like to take the value of the cell clicked (date) and pass it to another page.
This is what i have so far on the code.
<% Do Until rsCustomersList.EOF%>
<tr>
<td bgcolor="f7efde" align=center>
<%= rsCustomersList("FirstName
<%= " " %>
<%= rsCustomersList("LastName"
</td>
<td bgcolor="f7efde" align=center>
<%= rsCustomersList("Username"
</td>
<td bgcolor="f7efde" align=center>
<% astring = "<A HREF=bydate.asp?action=Set
<%= astring %>
<%= rsCustomersList("Date")%>
</td>
</tr>
<%
rsCustomersList.MoveNext
count = count + 1
Loop
%>
Thanks for any help
Magoo
Tom, you are right about the "s, but more with the =Setdate=" synatax. Try this instead;
<% astring = "<A HREF=bydate.asp?action="Se tDate=' & rsCustomersList("Date") & '">Click Me</A>" %>
Mark
<% astring = "<A HREF=bydate.asp?action="Se
Mark
Mark/magoo2:
Actually, I think passing the date format is probably going to be a big old pain, probably something like:
<% astring = "<A HREF=bydate.asp?action="Se tDate=' & Server.HTMLEncode(rsCustom ersList("D ate")) & '">Click Me</A>" %>
(if that's the right syntax)
Tom
Actually, I think passing the date format is probably going to be a big old pain, probably something like:
<% astring = "<A HREF=bydate.asp?action="Se
(if that's the right syntax)
Tom
The date format is going to wreak havok on the browsers... I know the data will display differently in other countries, but here in the good old US of A, it will appear as 12/17/99 In Perl you can escape the slashes, I don't know if HTMLEncode will pass the date string correctly.
One way to find out! :-)
One way to find out! :-)
Try this;
<%
SetDate = Server.HTMLEncode(Date())
%>
<A HREF="bydate.asp?action=<% = SetDate %>">Click Me</A>
Mark
<%
SetDate = Server.HTMLEncode(Date())
%>
<A HREF="bydate.asp?action=<%
Mark
As I though the HTMLEncode failed to encode the / properly, so you may want to just delete the / entirely;
<%@ language=VBScript%>
<%
SetDate = Server.HTMLEncode(Date())
SetDate = Replace(SetDate, "/" ,"")
%>
<A HREF="bydate.asp?action=<% = SetDate %>">Click Me</A>
<%@ language=VBScript%>
<%
SetDate = Server.HTMLEncode(Date())
SetDate = Replace(SetDate, "/" ,"")
%>
<A HREF="bydate.asp?action=<%
You want to use URLEncode not HTMLEncode to pass the date.
URLEncode replaces characters that cause problems in URLs (spaces, symbols, etc).
HTMLEncode replaces text with HTML for symbols that give HTML problems (caret signs, apostrophes)
<a href="bydate.asp?action=<% =server.ur lencode(da te)%>">Cli ck Me</a>
URLEncode replaces characters that cause problems in URLs (spaces, symbols, etc).
HTMLEncode replaces text with HTML for symbols that give HTML problems (caret signs, apostrophes)
<a href="bydate.asp?action=<%
Good catch, cw.
Tom
Tom
The HTMLEncode URLEndode syntax beat me up last week for a good hour... data storage and retrieval... In fact, I ended up using a suggestion by Tom instead;
<%
tText = objRS.Fields("text2")
tText = replace(replace(tText,vbCR LF,"<BR>") ," "," ")
Response.Write tText
%>
( I only needed to catch spaces and <cr>)
<%
tText = objRS.Fields("text2")
tText = replace(replace(tText,vbCR
Response.Write tText
%>
( I only needed to catch spaces and <cr>)
ASKER
Thanks for all the comments
The code I pasted earlier doesnt have to stay the way it is (or even close). I just want to pass the value of the date field to the next page the easiest way possible.
It will be using the value of the date field in this SQL query on the next page.
SQLQuery = "SELECT * FROM Customers WHERE Date = #" & setDate & "# ORDER BY LastName"
Is there a painless way to do that?
Many thanks
Magoo
The code I pasted earlier doesnt have to stay the way it is (or even close). I just want to pass the value of the date field to the next page the easiest way possible.
It will be using the value of the date field in this SQL query on the next page.
SQLQuery = "SELECT * FROM Customers WHERE Date = #" & setDate & "# ORDER BY LastName"
Is there a painless way to do that?
Many thanks
Magoo
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<a href="mysearchpage.asp?myd ate=<%=ser ver.urlenc ode("Date" )%>">Look up <% Date %></a>
' MySearchPage.asp
<%
Dim myDate, Action
myDate = request.querystring("mydat e")
sqlquery = "select * from customers where datefield = #" & myDate & "# order by lastname"
' MySearchPage.asp
<%
Dim myDate, Action
myDate = request.querystring("mydat
sqlquery = "select * from customers where datefield = #" & myDate & "# order by lastname"
ASKER
Thank you for the comments. I am accepting clockwatchers comments for the answer (it worked first) , but would like to give you other guys some points for all the info youve given.
One more question...this bit below works great for passing one variable(?) , how would I alter it to pass two variables (Date and Time).
<a href="bydate.asp?mydate=<% =server.ur lencode(rs CustomersL ist("Date" ))%>"><%= rsCustomersList("Date")%>< /a>
Thanks for all the help :)
Magoo
One more question...this bit below works great for passing one variable(?) , how would I alter it to pass two variables (Date and Time).
<a href="bydate.asp?mydate=<%
Thanks for all the help :)
Magoo
<a href="bydate.asp?mydate=<% =server.ur lencode(rs CustomersL ist("Date" ))%>&myTim e=<%rsCust omerList(T ime")%>">< %= rsCustomersList("Date")%>< /a>
Mark
Mark
I just thought of something... if you are going to do a query on a date field in a dB, what is the search going to find if the look-up string is like this;
myDate = 12%2F17%2F99
How is the dB going to handle the ascii characters on a query?
In other words, the date is going to pass this value to the SQL query as it is, unless you re-process it, or use my suggestion and use Replace()
Mark
myDate = 12%2F17%2F99
How is the dB going to handle the ascii characters on a query?
In other words, the date is going to pass this value to the SQL query as it is, unless you re-process it, or use my suggestion and use Replace()
Mark
Mark,
Request.Querystring automatically handles the conversion back to normal. Otherwise, you'd end up with junk when handling your forms on a GET request.
If you actually wanted to use the encoded version of the string, you'd have to use request.servervariables("Q UERY_STRIN G") and parse it yourself. That's what the request.querystring object does for you. It parses the querystring into a collection of name/value pairs that are url-DEcoded.
Request.Querystring automatically handles the conversion back to normal. Otherwise, you'd end up with junk when handling your forms on a GET request.
If you actually wanted to use the encoded version of the string, you'd have to use request.servervariables("Q
OK... you've lost me. Obviously this would only work if the query was going to be on 1/1/2000;
<a href="mysearchpage.asp?myd ate=<%=ser ver.urlenc ode("1/1/2 000")%>">L ook up 1/1/2000</a>
So, we use this instead;
<a href="mysearchpage.asp?myd ate=<%=ser ver.urlenc ode("Date" )%>">Look up <% Date %></a>
Whereas when we pass 'mydate' to mysearchpage.asp it is interpreted as either 12%2F17%2F99 or 12/17/99. Using Request.QueryString() with Get on a form submit would decode the 12%2F17%2F99 string to 12/17/99?
I just don't see where this will work... If you only want to pass the date as a string var than you could just use this; (without any encoding)
<form method="get">
<A HREF="bydate.asp?action=<% = Date() %>">Click Me</A>
</form>
This works fine in a simple world of browsers because we all know that the / is interpreted fine.
Mark
<a href="mysearchpage.asp?myd
So, we use this instead;
<a href="mysearchpage.asp?myd
Whereas when we pass 'mydate' to mysearchpage.asp it is interpreted as either 12%2F17%2F99 or 12/17/99. Using Request.QueryString() with Get on a form submit would decode the 12%2F17%2F99 string to 12/17/99?
I just don't see where this will work... If you only want to pass the date as a string var than you could just use this; (without any encoding)
<form method="get">
<A HREF="bydate.asp?action=<%
</form>
This works fine in a simple world of browsers because we all know that the / is interpreted fine.
Mark
Mark,
I think you're completely missing the difference between URLEncode and HTMLEncode.
An URL is the request. So '/' isn't fine in an url querystring--- it's a directory separator (e.g., http://www.somewhere.com/directory/a.html?myvar=/what/ever/ is not fine-- some browsers may take it, but some may not). The reason URLEncode alters the '/' symbol is because that it IS NOT OKAY in an URL. That's like saying '?' is fine because browsers simply write out a ?. A '?' is fine in HTML, but it's definitely not fine in an URL. It demarcates the beginning of the querystring.
That's why there are two functions-- URLEncode and HTMLEncode. URLEncode makes sure that the URL doesn't contain any characters that may mess with it. The space is a perfect example of a character that has to be url-encoded. The following will work fine in Internet Explorer, but won't work in Netscape-- you'll get a malformed URL request.
http://www.somewhere.com/mypage.asp?v1=hello there&v2=whatever
So the safest way to handle a querystring in ALL CASES is to URL encode it.
On the other end, when you retrieve the variables passed within a querystring-- Request.Querystring automatically takes care of unencoding it for you.
Try this simple test-- from your own post above.
bydate.asp
-----------
<html>
<body>
The complete untouched/unparsed querystring was: <%=request.servervariables ("QUERY_ST RING")%><B R><BR>
But, Request.querystring parses it and gives me this as the action variable: <%=request.querystring("ac tion")%>
</body>
</html>
And call it with the following:
http://www.wherever.com/bydate.asp?action=12%2F17%2F99
The request.querystring will parse the querystring, unencode it and produce 12/17/99. It's the same thing that happens when you use GET. The browser's url-encode everything behind the scenes and then pass it to the server. Try the following:
anothertest.asp
---------------
<html>
<body>
The complete untouched querystring was: <%=request.servervariables ("QUERY_ST RING")%><B R><BR>
But, Request.querystring parses it and gives me this as the action variable: <%=request.querystring("ac tion")%>
<br><br>
<form method="GET" action="anothertest.asp">
<input name="action" value="12/17/99">
<input type="submit">
</form>
</body>
</html>
Press the submit button, it will GET itself and you'll notice that the browser has url-encoded the 12/17/99 behind the scenes for you-- because the "/" isn't okay in an URL.
-------------------------- ---------- ----
HTMLEncode is a completely different function and has nothing to do with URLs. HTMLEncode deals with encoding characters that are special to HTML and may cause the HTML parser to choke. You're right it wouldn't touch the '/' or the '?', because those don't have any special meaning within HTML. Its main use is to replace the caret symbols '<' and '>', but it also replaces a few more symbols that might choke the browser.
I think you're completely missing the difference between URLEncode and HTMLEncode.
An URL is the request. So '/' isn't fine in an url querystring--- it's a directory separator (e.g., http://www.somewhere.com/directory/a.html?myvar=/what/ever/ is not fine-- some browsers may take it, but some may not). The reason URLEncode alters the '/' symbol is because that it IS NOT OKAY in an URL. That's like saying '?' is fine because browsers simply write out a ?. A '?' is fine in HTML, but it's definitely not fine in an URL. It demarcates the beginning of the querystring.
That's why there are two functions-- URLEncode and HTMLEncode. URLEncode makes sure that the URL doesn't contain any characters that may mess with it. The space is a perfect example of a character that has to be url-encoded. The following will work fine in Internet Explorer, but won't work in Netscape-- you'll get a malformed URL request.
http://www.somewhere.com/mypage.asp?v1=hello there&v2=whatever
So the safest way to handle a querystring in ALL CASES is to URL encode it.
On the other end, when you retrieve the variables passed within a querystring-- Request.Querystring automatically takes care of unencoding it for you.
Try this simple test-- from your own post above.
bydate.asp
-----------
<html>
<body>
The complete untouched/unparsed querystring was: <%=request.servervariables
But, Request.querystring parses it and gives me this as the action variable: <%=request.querystring("ac
</body>
</html>
And call it with the following:
http://www.wherever.com/bydate.asp?action=12%2F17%2F99
The request.querystring will parse the querystring, unencode it and produce 12/17/99. It's the same thing that happens when you use GET. The browser's url-encode everything behind the scenes and then pass it to the server. Try the following:
anothertest.asp
---------------
<html>
<body>
The complete untouched querystring was: <%=request.servervariables
But, Request.querystring parses it and gives me this as the action variable: <%=request.querystring("ac
<br><br>
<form method="GET" action="anothertest.asp">
<input name="action" value="12/17/99">
<input type="submit">
</form>
</body>
</html>
Press the submit button, it will GET itself and you'll notice that the browser has url-encoded the 12/17/99 behind the scenes for you-- because the "/" isn't okay in an URL.
--------------------------
HTMLEncode is a completely different function and has nothing to do with URLs. HTMLEncode deals with encoding characters that are special to HTML and may cause the HTML parser to choke. You're right it wouldn't touch the '/' or the '?', because those don't have any special meaning within HTML. Its main use is to replace the caret symbols '<' and '>', but it also replaces a few more symbols that might choke the browser.
cw:
Good explanation. Thanks!
Tom
Good explanation. Thanks!
Tom
Thanks CW, you are a great professor... ;-) I understand much more clearly now the concepts of URL vs. HTML Encode and it's use with request.querystring().
Thanks,
Mark
Thanks,
Mark
<% astring = "<A HREF=bydate.asp?action=Set
That SHOULD generate something like the following HTML code for each entry:
<a href=bydate.asp?action=Set
You may run into issues with "s (since there are none) and encoding the date, depending on it's format in the database.
Is this what you are trying to do?
Tom