Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-09-2004, 12:07 PM   #1 (permalink)
buchannon
Registered User
 
buchannon's Avatar
 
Join Date: Nov 2004
Posts: 43
buchannon is on a distinguished road
Cookie help with ASP...

Hello again... Sorry, this is like my 5th post in the last 2 days, but thanks for all the help. I have this so far:

Quote:
<%@ Language=VBScript %>
<%
if request.cookies("size")="" then
response.cookies("size")="12px"
response.cookies("size").expires=#December 25,2004#
size="12px"
else
size=request.cookies("size")
end if
%>

<HTML>

<HEAD>

<body>

<%
response.write("Lets see what I can learn using ASP... ")
%>
<p><BR>

<%
response.write("<body bgcolor=yellow>")
%>
<br>
<%
dim yourname
yourname="George Bush"
response.write("<a href='http://www.unco.edu/dss/testlink.asp?name=" & yourname & "'>Did this work?</a>")
response.write(" " & yourname)
%>

<br>
<p>

</script>
</head>
<%
response.write("This is what the cookie is showing for size: " & size)
%>
<body>
<form mehtod="get" action="test.asp">
<select title="Select a Font Size" name="fontsize" id="FontSize" style="width:75px" class="layoutMenu">
<option value="5" <% if request.querystring("fontsize")="5" then response.write("selected") end if %> >5</option>
<option value="11px" <% if request.querystring("fontsize")="11px" then response.write("selected") end if %> >11px</option>
<option value="12px" <% if request.querystring("fontsize")="12px" then response.write("selected") end if %> >12px</option>
<option value="13px" <% if request.querystring("fontsize")="13px" then response.write("selected") end if %> >13px</option>
<option value="14px" <% if request.querystring("fontsize")="14px" then response.write("selected") end if %> >14px</option>
<option value="15px" <% if request.querystring("fontsize")="15px" then response.write("selected") end if %> >15px</option>
<option value="16px" <% if request.querystring("fontsize")="16px" then response.write("selected") end if %> >16px</option>
<option value="17px" <% if request.querystring("fontsize")="17px" then response.write("selected") end if %> >17px</option>
<option value="18px" <% if request.querystring("fontsize")="18px" then response.write("selected") end if %> >18px</option>
<option value="19px" <% if request.querystring("fontsize")="19px" then response.write("selected") end if %> >19px</option>
<option value="xx-large" <% if request.querystring("fontsize")="xx-large" then response.write("selected") end if %> >extra Large</option>-->
</select>
<%
response.cookies("size")= request.querystring("fontsize")
response.cookies("size").expires=#December 12,2004#
%>
<input type="submit" value="GO TO IT!">
</form>


<%
response.write("This is your text: " & request.querystring("fontsize"))
%>

<div id="test">
Here is some text
<br>

<br>
<%
response.write("<center> <font size='" & request.querystring("fontsize") & "'>")
%>
Here is some text
<%
response.write("<center> Your size of text is: " & request.querystring("fontsize") & ". Do you like it?")
%>

<table id="tabletest"><tr><td>did it work on me?</td></tr></table>
Bla Bla

</div>

</BODY>

</HTML>
It's a lot closer to what I want it to be but still missing some little things. Right now I'm having a problem with the cookie lagging behind the browser one refresh. For instance, I can chance the font size from 14px to 16px and submit the form. The text size will change on the page, but the cookie value still shows up as 14px after submit until I refresh the page or hit submit again.

Since I'm using the URL value to store the user's text size, this defeats the whole purpose of using cookies in the first place, to store the user's prefrence incase they come back to the page. Is there something I can do to make the cookie remain current right after the first submit?
buchannon is offline   Reply With Quote
Old 11-09-2004, 12:23 PM   #2 (permalink)
buchannon
Registered User
 
buchannon's Avatar
 
Join Date: Nov 2004
Posts: 43
buchannon is on a distinguished road
w00t I figured it out by myself! :rock: I just had to mix some of the commands around and delete a line.

But yet another problem arises. When I do close the browser and re-open it to the page, when I make this call shouldn't it retreive that cookie value it just had?
Quote:
size=request.cookies("size")
When I do close/reopen browser, the line using the variable 'size' comes up blank.
buchannon is offline   Reply With Quote
Old 11-09-2004, 12:26 PM   #3 (permalink)
rdove
Masked Moderator
 
rdove's Avatar
 
Join Date: May 2002
Location: Indianapolis, IN
Posts: 260
rdove is on a distinguished road
I think you are running into a client side page cache issue. I have been there before as well.

You can use:

Response.CacheControl = "no-cache"

This will tell the browser not to cache that page. This will force it to relaod the page and get the most current information.
__________________
~Ryan

rdove is offline   Reply With Quote
Old 11-10-2004, 09:37 AM   #4 (permalink)
buchannon
Registered User
 
buchannon's Avatar
 
Join Date: Nov 2004
Posts: 43
buchannon is on a distinguished road
Ok I got all the cookie crap worked out... for now. Just needed some if statements in there, here is the code if anyone is interested:
Quote:
<% dim size
%>
<%
if request.cookies("size")="" then
response.cookies("size")="12px"
response.cookies("size").expires=#December 25,2004#
size="12px"
else
size=request.cookies("size")
end if
%>
<%
if request.querystring("fontsize")= "" then
size = request.cookies("size")
else
response.cookies("size")=request.querystring("font size")
response.cookies("size").expires=#December 25,2004#
size = request.cookies("size")
end if
%>
buchannon is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP Links buchannon MS Technologies ( ASP, VB, C#, .NET ) 12 11-09-2004 12:24 PM
New Tutorials: ASP Strings, and Visual Studio/VB.NET sde Code Newbie News 0 03-25-2004 06:37 PM
New Java and ASP Tutorials sde Code Newbie News 2 03-15-2004 08:02 PM
Php Vs. Asp sde PHP 6 06-06-2003 06:02 PM


All times are GMT -8. The time now is 10:50 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting