Please Help, I am Stuccked

Discussion in 'C#' started by bodongo, May 25, 2007.

  1. #1
    I am a really newbie to ASP. I dont know how could i be able to remove the cookie ( with keys ). If i choose to make it expire instead of making blank, it simply donot allow me to add more id's to the newly created list ( or the new list contains more than double keys that were before makig cookie to blank.) I know its a raw coding, but i am a new one and want help. Please someone suggest: confused:

    This is the code :

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <%
    if (not(len(Request.Cookies("ivalue"))=0)) then
    Response.Cookies("ivalue")=Request.Cookies("ivalue")+1
    else
    Response.Cookies("ivalue")=1
    end if

    ivah=Request.Cookies("ivalue")

    ' -----------------Adding Cookie------------------------

    if Request.QueryString("act")="ad" then
    cbt=0
    for each k in Request.Cookies("mycookie")
    If (Request.Cookies("mycookie")(k)=Request.QueryString("id")) Then
    cbt=cbt+1
    End If
    next
    if(cbt=0) then
    Response.Cookies("mycookie")("id" & ivah)= Request.QueryString("id")
    end if
    end if


    '----------------------- Deleting All Cookies ----------------------
    if Request.QueryString("id")="removeall" and Request.QueryString("act")="rem" then
    Response.Cookies("mycookie")=""
    elseif(Request.QueryString("act")="rem") then

    '----------------------- Deleting Selected Cookie ----------------------
    ' if(Request.QueryString("act")="rem") then
    ' if(Request.Cookies("mycookie")("id" & iva2)=Request.QueryString("id")) then
    'REMOVE ITEM FROM LIST

    ' Dim k
    'store all entries from the cookie in a temporary dictionary

    for each k in Request.Cookies("mycookie")
    If (Request.Cookies("mycookie")(k)<>Request.QueryString("id")) Then
    Session("myCookie" & tot+1)=Request.Cookies("mycookie")(k)
    tot=tot+1
    End If
    next
    'delete all entries from the cookie
    Response.Cookies("mycookie")=""
    'copy everything back into cookie except for the deleted item
    for i = 1 to tot
    Response.Cookies("mycookie")("id" & i)=Session("myCookie" & i)
    'Response.Write("id" & i & " : " & Request.Cookies("mycookie")("id" & i) & "<br />")
    Next
    End If

    ' Response.Cookies("mycookie")("id" & iva2)=""


    ' -----------------Displaying Cookie------------------------

    ivan=0
    iwan=0
    cnttt=0
    for each x in Request.Cookies
    if Request.Cookies(x).HasKeys then
    ivan=0
    for each y in Request.Cookies(x)
    ivan=ivan+1
    if(len(Request.Cookies("mycookie")("id" & ivan))>2) then
    if(iwan<3) then
    response.write("Portfolio" & iwan+1 & "=" & Request.Cookies("mycookie")("id" & ivan) & "<br />")
    iwan=iwan+1
    end if
    cnttt=cnttt+1
    end if
    next
    else
    ' Response.Write(x & "=" & Request.Cookies(x) & "<br />")
    end if
    next
    Response.Write("<br />Total -" & cnttt & " : in Portfolio<br /><br />")%>
    <a href="javascript:;" onClick="sh();">Empty Portfolio</a>
    <% Response.Write("<br /><a href=redir.asp>View Portfolio</a><br />")%>
     
    bodongo, May 25, 2007 IP
  2. bodongo

    bodongo Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Please lt me know if there is anything confising/missing in the code. Thanks
     
    bodongo, May 25, 2007 IP
  3. N_F_S

    N_F_S Active Member

    Messages:
    2,475
    Likes Received:
    56
    Best Answers:
    0
    Trophy Points:
    90
    #3
    I bet this is taken from some asp website?

    You can use cookies with much less lines of script, why don't you use different cookie names, isntead of adding ids/keys and searching for each of them ?
     
    N_F_S, May 25, 2007 IP
  4. bodongo

    bodongo Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Very first thing : It is not taken from any website.

    Second : Requirement is there to store anonymous number of id's. I am not sure of reading cookie variables dynamically. So I used key function. Now when I added some id's, no problem, i remove 1 or 2, still its working, but aftr this if i try to add new id, it doesnt shows new id or shows unexpected results
     
    bodongo, May 25, 2007 IP
  5. bodongo

    bodongo Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    please anyone help me, i am really not finding any solution.
     
    bodongo, May 25, 2007 IP
  6. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #6
    Well - you already have the code, hehe - you just need to enumerate over your keys and set the values to blank...

    for each k in Request.Cookies
    response.cookies(k)=""
    next
     
    ccoonen, May 26, 2007 IP