?
Solved

Cookie returning null error

Posted on 2006-11-20
4
Medium Priority
?
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
bprojoe earned 2000 total points
ID: 17980595
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
ID: 17980973
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
ID: 17981143

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

0
 
LVL 4

Expert Comment

by:Steve Sirica
ID: 17981174
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

770 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