Welcome to Dream.In.Code
Getting Help is Easy!

Join 107,669 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,043 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Cookie Problem

 
Reply to this topicStart new topic

Cookie Problem

cbr4rusty
post 25 Jun, 2008 - 08: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 - 08:31 AM
User is offlineProfile CardPM

Go to the top of the page


rgfirefly24
post 25 Jun, 2008 - 10:39 AM
Post #2


D.I.C Regular

Group Icon
Joined: 7 Apr, 2008
Posts: 307



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

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/29/08 11:01PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month