Solved

Cookie returning null error

Posted on 2006-11-20
4
222 Views
Last Modified: 2010-05-18
1.I have saved 2 values in a cookie like this:
If Request.Cookies("LoginSettings") Is Nothing Then
            Response.Cookies("LoginSettings")("DB") = rbDatabases.SelectedItem.Value
            Response.Cookies("LoginSettings")("Language") = rbLan.SelectedItem.Value
            Response.Cookies("LoginSettings").Expires = DateTime.Now.AddDays(7)
        End If

2. I go to my cookie folder and I see the cookie values:
   LoginSettings DB=SQL&Language=English localhost\<bunch of numbers here>

3. Want to read them back:
 If Not Page.IsPostBack Then
            If Request.Cookies("LoginSettings") IsNot Nothing Then
                If Request.Cookies("LoginSettings")("DB") IsNot Nothing Then
                   rbSystems.SelectedItem.Value = Request.Cookies("LoginSettings")("DB")  ****This line returns null***
                End If
                If Request.Cookies("LoginSettings")("Language") IsNot Nothing Then
                    rbLan.SelectedItem.Value = Request.Cookies("Language").Value.ToString

                End If

            End If
        End If


***But I keep getting Null Error on rbSystems.SelectedItem.Value = Request.Cookies("LoginSettings")("DB").
what am i missing?

0
Comment
Question by:Camillia
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
bprojoe earned 500 total points
Comment Utility
Try something like this......

If Request.Cookies("LoginSettings") Is Nothing Then
dim cookie as new httpcookie("LoginSetting")
cookie.values("DB") = rbDatabases.SelectedItem.Value
            cookie.values("Language") = rbLan.SelectedItem.Value
            cookie.values.Expires = DateTime.Now.AddDays(7)
Response.AppendCookie(cookie)
else
dim cookie as httpcookie = request.cookies("LoginSetting")
cookie.values("DB") = rbDatabases.SelectedItem.Value
            cookie.values("Language") = rbLan.SelectedItem.Value
            cookie.values.Expires = DateTime.Now.AddDays(7)
Response.AppendCookie(cookie)

        End If
0
 
LVL 4

Expert Comment

by:Steve Sirica
Comment Utility
If the Request.Cookies("LoginSettings") Is Nothing shouldn't the Response.AppendCookie(cookie) line be Response.Cookies.add(cookie)?

 
0
 
LVL 7

Author Comment

by:Camillia
Comment Utility

I dont know, should it be append or add?? does it make a diff??

0
 
LVL 4

Expert Comment

by:Steve Sirica
Comment Utility
Not sure.  I've always understood it that you append to something that exists and add something that's new.  Using that logic, if Request.Cookies("LoginSettings") Is Nothing there's nothing to append too?
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now