Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Javascript and cookies

Reply
Thread Tools

Javascript and cookies

 
 
Wardeaux
Guest
Posts: n/a
 
      07-02-2004
I set a cookie in my code behind:

Dim cookieFocus As New HttpCookie("PMFocus")
cookieFocus.Value = "D"

Response.Cookies.Add(cookieFocus)

I read the cookie in my html page:
function doFocus(str)
{ var allcookies = document.cookie;
var pos = allcookies.indexOf("PMFocus=");
var mydate = new Date();
mydate.setFullYear(2000);
alert(allcookies);
if (pos != -1)
{
var start = pos + 8;
var end = allcookies.indexOf(";",start);
if (end == -1) end = allcookies.length;
var Myvalue = allcookies.substring(start,end);
alert(Myvalue);
if (Myvalue == "D")
{
alert("Found Cookie");
document.all(str).focus();
}
}
document.cookie = "PMFocus=E"
alert("here");
}

When I try to set the cookie to a new value it just creates new cookie by
the same name...
and when I change the value from my codebehind, it doesn't change the one
created by my clientside javascript
Any clues how to get them to work on the same cookie?

MTIA
wardeaux



 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      07-03-2004
"Wardeaux" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I set a cookie in my code behind:
>
> Dim cookieFocus As New HttpCookie("PMFocus")
> cookieFocus.Value = "D"
>
> Response.Cookies.Add(cookieFocus)
>
> I read the cookie in my html page:
> function doFocus(str)
> { var allcookies = document.cookie;
> var pos = allcookies.indexOf("PMFocus=");
> var mydate = new Date();
> mydate.setFullYear(2000);
> alert(allcookies);
> if (pos != -1)
> {
> var start = pos + 8;
> var end = allcookies.indexOf(";",start);
> if (end == -1) end = allcookies.length;
> var Myvalue = allcookies.substring(start,end);
> alert(Myvalue);
> if (Myvalue == "D")
> {
> alert("Found Cookie");
> document.all(str).focus();
> }
> }
> document.cookie = "PMFocus=E"
> alert("here");
> }
>
> When I try to set the cookie to a new value it just creates new cookie by
> the same name...
> and when I change the value from my codebehind, it doesn't change the one
> created by my clientside javascript
> Any clues how to get them to work on the same cookie?


I think you'll have to delete the cookie on the client side first.
--
John Saunders
johnwsaundersiii at hotmail


 
Reply With Quote
 
 
 
 
Wardeaux
Guest
Posts: n/a
 
      07-06-2004
Thanks Simon... will give it a try...
wardeaux

"Simon Wallis" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> It is possible but tricky, I had it working some time ago in an old ASP

application. I can't remember all the necessary tricks, but try doing things
like making the cookie name all uppercase or all lowercase letters and is
only alphanumeric (ie., contains no characters that would get url-encoded).
Also try setting all properties such as domain, path, etc.
>
> It is definitely possible.
>
> Simon.
>
>
> "Wardeaux" wrote:
>
> > I set a cookie in my code behind:
> >
> > Dim cookieFocus As New HttpCookie("PMFocus")
> > cookieFocus.Value = "D"
> >
> > Response.Cookies.Add(cookieFocus)
> >
> > I read the cookie in my html page:
> > function doFocus(str)
> > { var allcookies = document.cookie;
> > var pos = allcookies.indexOf("PMFocus=");
> > var mydate = new Date();
> > mydate.setFullYear(2000);
> > alert(allcookies);
> > if (pos != -1)
> > {
> > var start = pos + 8;
> > var end = allcookies.indexOf(";",start);
> > if (end == -1) end = allcookies.length;
> > var Myvalue = allcookies.substring(start,end);
> > alert(Myvalue);
> > if (Myvalue == "D")
> > {
> > alert("Found Cookie");
> > document.all(str).focus();
> > }
> > }
> > document.cookie = "PMFocus=E"
> > alert("here");
> > }
> >
> > When I try to set the cookie to a new value it just creates new cookie

by
> > the same name...
> > and when I change the value from my codebehind, it doesn't change the

one
> > created by my clientside javascript
> > Any clues how to get them to work on the same cookie?
> >
> > MTIA
> > wardeaux
> >
> >
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Give Request.Cookies and Response.Cookies is there any reason to use another method to use cookies? _Who ASP .Net 7 09-18-2008 07:49 PM
Persistant cookies and non-persistant cookies. archana ASP .Net 1 05-25-2007 08:43 AM
Response.Cookies vs Request.Cookies Alex Nitulescu ASP .Net 1 02-03-2005 09:43 AM
Persistent Cookies vs. session cookies Andy Fish Java 3 11-06-2003 10:44 AM
Good Cookies bad Cookies? AK Computer Support 23 10-26-2003 05:20 AM



Advertisments