yes .................i m working for remember me
even i want the the username n password cookie is found the remember me checkbox should me clicked
on postback i m creating cookies n on page load i m checking for the cookie.......so plz check my code its not working for password n remember me checkbox
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If Request.Cookies("myCookie") IsNot Nothing Then
Debug.WriteLine("Cookie created")
Dim cookie As HttpCookie = Request.Cookies.[Get]("myCookie")
CType(Login1.FindControl("UserName"), TextBox).Text = cookie.Values("USR")
CType(Login1.FindControl("ChkRememberMe"), CheckBox).Checked = Session("RememberME")
' CType(Login1.FindControl("Password"), TextBox).Text = cookie.Values("PWD1")
' CType(Login1.FindControl("Password"), TextBox).Text = Request.Cookies("PWD1").Value.ToString()
Debug.WriteLine(Request.Cookies("PWD1"))
End If
Response.Cache.SetNoStore()
End If
If IsPostBack Then
Dim checkME As Boolean = CType(Login1.FindControl("ChkRememberMe"), CheckBox).Checked
Session("RememberME") = checkME
If checkME = True Then
Dim myCookie As New HttpCookie("myCookie")
Debug.WriteLine("Checkbox is checked")
Response.Cookies.Add(myCookie)
Dim CUserName As String = CType(Login1.FindControl("UserName"), TextBox).Text
Dim CPassword As String = CType(Login1.FindControl("Password"), TextBox).Text
myCookie.Values.Add("USR", CUserName)
myCookie.Values.Add("PWD1", CPassword)
Dim dtExpiry As DateTime = DateTime.Now.AddDays(30)
Response.Cookies("myCookie").Expires = dtExpiry
Else
Debug.WriteLine("cookie else")
Response.Cookies("UsrName").Expires = DateTime.Now.AddMonths(-1)
Response.Cookies("PWD").Expires = DateTime.Now.AddMonths(-1)
End If
End If
thnx for the help
i can give you a better and less code solution to this problem.
in page load Event
If IsPostBack = False Then
If Request.Browser.Cookies Then
If Request.Cookies("UserName") IsNot Nothing Then
txtEmailID.Text = Request.Cookies("UserName").Value.ToString()
End If
If Request.Cookies("PassWord") IsNot Nothing Then
txtPassword.Text = Request.Cookies("PassWord").Value.ToString()
flag = LoginDirectly(txtEmailID.Text, txtPassword.Text)'This will check from user
If flag Then
Response.Redirect("Default.aspx")
Else
lblLoginMsg.Text ="Invalid EmailID or password"
txtPassword.Text = ""
End If
End If
End If
End If
and in login button
If Request.Browser.Cookies Then
Response.Cookies("UserName").Expires = DateTime.Now.AddDays(30)
Response.Cookies("UserName").Value = txtEmailID.Text
End If
If chkRemMe.Checked Then
Response.Cookies("PassWord").Expires = DateTime.Now.AddDays(30)
Response.Cookies("PassWord").Value = txtPassword.Text
End If
' do the login proccess
and in logout button
If Request.Cookies("PassWord") IsNot Nothing Then
Response.Cookies("PassWord").Expires = DateTime.Now.AddDays(-30)
End If
'' and sign out here
Please "Mark as Answer" if this post helps.Thank You :)
Smadhu
Member
510 Points
985 Posts
how to assign value to text box from cookie with textbox
May 09, 2012 07:24 AM|LINK
how to assign value to text box from cookie with textmode is password
<asp:TextBox ID="Password" CssClass="TextBox" runat="server"></asp:TextBox>
vb.net
CType(Login1.FindControl("Password"), TextBox).Text = cookie.Values("PWD1")
it shows me value in password textbox but when i add textmode="password"
it doesnot shows me the value.................so how i can show value in textbox whose textmode is password.
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: how to assign value to text box from cookie with textbox
May 09, 2012 07:30 AM|LINK
hi
try this
CType(Login1.FindControl("Password"), TextBox).Text = Request.Cookies("PWD1").Value.ToString()
Smadhu
Member
510 Points
985 Posts
Re: how to assign value to text box from cookie with textbox
May 09, 2012 07:41 AM|LINK
sorry but above code is not working??
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: how to assign value to text box from cookie with textbox
May 09, 2012 07:50 AM|LINK
okay as i assume you create you cookie as following
Dim cookie As HttpCookie = New HttpCookie("CookieName") cookie.Values.Add("PWD1", "wtEver") Response.Cookies.Add(cookie)and try this now
CType(Login1.FindControl("Password"), TextBox).Text = Response.Cookies("CookieName").Values("PWD1")
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: how to assign value to text box from cookie with textbox
May 09, 2012 07:59 AM|LINK
if you want a scenario for remember me login i can help you with that.
Smadhu
Member
510 Points
985 Posts
Re: how to assign value to text box from cookie with textbox
May 09, 2012 08:07 AM|LINK
yes .................i m working for remember me even i want the the username n password cookie is found the remember me checkbox should me clicked on postback i m creating cookies n on page load i m checking for the cookie.......so plz check my code its not working for password n remember me checkbox Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then If Request.Cookies("myCookie") IsNot Nothing Then Debug.WriteLine("Cookie created") Dim cookie As HttpCookie = Request.Cookies.[Get]("myCookie") CType(Login1.FindControl("UserName"), TextBox).Text = cookie.Values("USR") CType(Login1.FindControl("ChkRememberMe"), CheckBox).Checked = Session("RememberME") ' CType(Login1.FindControl("Password"), TextBox).Text = cookie.Values("PWD1") ' CType(Login1.FindControl("Password"), TextBox).Text = Request.Cookies("PWD1").Value.ToString() Debug.WriteLine(Request.Cookies("PWD1")) End If Response.Cache.SetNoStore() End If If IsPostBack Then Dim checkME As Boolean = CType(Login1.FindControl("ChkRememberMe"), CheckBox).Checked Session("RememberME") = checkME If checkME = True Then Dim myCookie As New HttpCookie("myCookie") Debug.WriteLine("Checkbox is checked") Response.Cookies.Add(myCookie) Dim CUserName As String = CType(Login1.FindControl("UserName"), TextBox).Text Dim CPassword As String = CType(Login1.FindControl("Password"), TextBox).Text myCookie.Values.Add("USR", CUserName) myCookie.Values.Add("PWD1", CPassword) Dim dtExpiry As DateTime = DateTime.Now.AddDays(30) Response.Cookies("myCookie").Expires = dtExpiry Else Debug.WriteLine("cookie else") Response.Cookies("UsrName").Expires = DateTime.Now.AddMonths(-1) Response.Cookies("PWD").Expires = DateTime.Now.AddMonths(-1) End If End If thnx for the helpAmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: how to assign value to text box from cookie with textbox
May 09, 2012 08:20 AM|LINK
i can give you a better and less code solution to this problem.
in page load Event
If IsPostBack = False Then If Request.Browser.Cookies Then If Request.Cookies("UserName") IsNot Nothing Then txtEmailID.Text = Request.Cookies("UserName").Value.ToString() End If If Request.Cookies("PassWord") IsNot Nothing Then txtPassword.Text = Request.Cookies("PassWord").Value.ToString() flag = LoginDirectly(txtEmailID.Text, txtPassword.Text)'This will check from user If flag Then Response.Redirect("Default.aspx") Else lblLoginMsg.Text ="Invalid EmailID or password" txtPassword.Text = "" End If End If End If End Ifand in login button
If Request.Browser.Cookies Then Response.Cookies("UserName").Expires = DateTime.Now.AddDays(30) Response.Cookies("UserName").Value = txtEmailID.Text End If If chkRemMe.Checked Then Response.Cookies("PassWord").Expires = DateTime.Now.AddDays(30) Response.Cookies("PassWord").Value = txtPassword.Text End Ifand in logout button
If Request.Cookies("PassWord") IsNot Nothing Then Response.Cookies("PassWord").Expires = DateTime.Now.AddDays(-30) End If '' and sign out hereSmadhu
Member
510 Points
985 Posts
Re: how to assign value to text box from cookie with textbox
May 09, 2012 08:29 AM|LINK
Prb is Assign Value to Asp.Net TextBox with mode="Password" in vb.net
CType(Login1.FindControl("Password"), TextBox).Text = cookie.Values("PWD1")
Me.Password.Attributes("value") = "YourPassword"
I try all above code but its not working
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: how to assign value to text box from cookie with textbox
May 09, 2012 08:43 AM|LINK
but if you keep that , when you come again it will sign in automatically ,, in my senario once he loged out no need for password .
when he come back he will find his email and type his password
the remember me is for staying login for 30 days . this is my senario.
once he logged out he must enter his password again
Smadhu
Member
510 Points
985 Posts
Re: how to assign value to text box from cookie with textbox
May 09, 2012 08:51 AM|LINK
ya wht u r suggesting is perfectly correct............but rite now i m not able to get value in my password textbox.its coming blank for me
how can i show valus in password textbox with pasword mode
thnx