Welcome to Dream.In.Code
Become an Expert!

Join 150,105 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,900 people online right now. Registration is fast and FREE... Join Now!




Cookie Problem

 
Reply to this topicStart new topic

Cookie Problem

cbr4rusty
25 Jun, 2008 - 07:30 AM
Post #1

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 25

I can't seem to get my cookie to get a value...


First Form...
CODE

    protected void Button2_Click(object sender, EventArgs e)
    {
        HttpCookie cookie = new HttpCookie("SQL");
        cookie.Values.Add("Name", textCity.Text);
        cookie.Value=textCity.Text;
        cookie.Expires = DateTime.Now.AddDays(1);
        Response.Cookies.Add(cookie);

        Session["UserName"] = "alksdjf";
        Response.Redirect("Gridview.aspx");
      }


Second Form...
CODE

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["SQL"]!= null)
        {
            Response.Write(Request.Cookies["SQL"].Value);
        }
        if (Request.Cookies["SQL"]==null)
        {
            TextBox1.Text = "Cookie is Null";
        }
    }


Why won't this work??

This post has been edited by cbr4rusty: 25 Jun, 2008 - 07:31 AM
User is offlineProfile CardPM
+Quote Post

rgfirefly24
RE: Cookie Problem
25 Jun, 2008 - 09:39 AM
Post #2

D.I.C Regular
Group Icon

Joined: 7 Apr, 2008
Posts: 335



Thanked: 5 times
Dream Kudos: 150
My Contributions
QUOTE(cbr4rusty @ 25 Jun, 2008 - 08:30 AM) *

I can't seem to get my cookie to get a value...


First Form...
CODE

    protected void Button2_Click(object sender, EventArgs e)
    {
        HttpCookie cookie = new HttpCookie("SQL");
        cookie.Values.Add("Name", textCity.Text);
        cookie.Value=textCity.Text;
        cookie.Expires = DateTime.Now.AddDays(1);
        Response.Cookies.Add(cookie);

        Session["UserName"] = "alksdjf";
        Response.Redirect("Gridview.aspx");
      }


Second Form...
CODE

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["SQL"]!= null)
        {
            Response.Write(Request.Cookies["SQL"].Value);
        }
        if (Request.Cookies["SQL"]==null)
        {
            TextBox1.Text = "Cookie is Null";
        }
    }


Why won't this work??



your cookie is being set to nothing. Your creating a cookie called Name and assigning that one something, but from the looks of it the cookie SQL has nothing in it.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:54AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month