Friday, November 2, 2012

Remember me functionality in asp.net with VB.net using Cookies


 use the below code to save the userid and password deatils in cookies 

on login button:-

 If CheckBox1.Checked = True Then
                Response.Cookies("UName").Value = txtUserID.Text
                Response.Cookies("PWD").Value = txtPwd.Text
                Response.Cookies("UName").Expires = DateTime.Now.AddMonths(2)
                Response.Cookies("PWD").Expires = DateTime.Now.AddMonths(2)
End If


use the below code to Retrive the userid and password deatils From cookies 


on page load :-

  If Not IsPostBack Then
            If Request.Cookies("UName") IsNot Nothing Then
                txtUserID.Text = Request.Cookies("UName").Value
            End If
            If Request.Cookies("PWD") IsNot Nothing Then
                Dim pass As TextBox = DirectCast(Me.FindControl("txtPwd"), TextBox)
                pass.Attributes.Add("value", Request.Cookies("PWD").Value)
            
            End If
            If Request.Cookies("UName") IsNot Nothing AndAlso Request.Cookies("PWD") IsNot Nothing Then
                CheckBox1.Checked = True
            End If
        End If

No comments:

Post a Comment