Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with retrieving cookie in ASP.net

0 views
Skip to first unread message

SV

unread,
May 6, 2008, 11:31:06 PM5/6/08
to
I have a login form with “Remember me on this computer” checkbox. I am
creating cookie if checkbox is checked. My code is:

If chk_remember.Checked = True Then

Dim ckUserName As HttpCookie = New
HttpCookie("CTUserName")
ckUserName.Value = Trim(txt_unm.Text)
ckUserName.Expires =
System.DateTime.Now.AddYears(4)
Response.Cookies.Add(ckUserName)
ckUserName = Nothing

End If


Now I am retrieving cookie on page load. It always gives me blank text
box of username. I don’t understand why it gives null. Is that I am
doing anything wrong?
My code for retrieving cookie is:

If Not (Request.Cookies("CTUserName") Is Nothing) Then

txt_unm.Text = Request.Cookies("CTUserName").Value

End If

Any help will be appreciated.

Thanks,
SV

Mark Rae [MVP]

unread,
May 7, 2008, 6:26:32 AM5/7/08
to
"SV" <swet...@gmail.com> wrote in message
news:cc6341b9-3aa8-407c...@x19g2000prg.googlegroups.com...

> Any help will be appreciated.

Does this work: ?

txt_unm.Text = Server.HtmlEncode(Request.Cookies("CTUserName").Value)


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

SV

unread,
May 7, 2008, 9:59:05 PM5/7/08
to
Ahhh, It is solved now.

Thanks Mark.


On May 7, 6:26 pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:
> "SV" <swetav...@gmail.com> wrote in message

0 new messages