pnalinivenkat 0 Newbie Poster

I am using two textboxes and one checkbox to remmber my username in login page

My requirement is for the first time if user logs in and he checks the check box
when he login for next time based on his username the password should be filled
i have written code by using cookies ,but i am not able to achieve the task

<script language="javascript" type="text/javascript">
 
Private Function readCookie(ByValcookies) As function
     Dim txtuname As var =  document.getElementById("userName"c) 
     Dim txtpass As var =  document.getElementById("password"c) 
If document.cookie.length>0 And txtuname.value.length>0 Then
  ' check the index of the username that is entered by user in Username text box 
  Dim c_start As var = document.cookie.indexOf(txtuname.value) 
  If c_start<>-1 Then
    Dim c_end As var = document.cookie.indexOf(";",c_start) 
    If c_end=-1 Then
      c_end=document.cookie.length
    End If
    Dim value As var =  unescape(document.cookie.substring(c_start,c_end)) 
    Dim arr As var =  New Array(10) 
    arr= value.split("="c)
    ' if only 0ne equal sign is present that is default one 
    If arr(0)=txtuname.value And arr.length=2 Then
      txtpass.value=arr(1)
    End If
   ' if the password contain =(equal) signs in it 
    Private Function if(ByVal =(0) As arr = txtuname.value And arr.length > 2 ) As else
       Dim pass As var = arr(1) 
       For i = 2 To arr.length- 1  Step i + 1
          pass += arr(i)
       Next
       txtpass.value=pass
    End Function
    else
    
     txtpass.value=""
   
  Else 
    txtpass.value=""
  End If
Else 
  txtpass.value=""
End If
 
End Function
 
</script>
In button click

If chksave.Checked Then
            Dim cookie As HttpCookie = New HttpCookie(username.Text)

            Response.Cookies.Add(cookie)

            cookie.Values.Add("", password.Text + ";")

            Response.Cookies(username.Text).Expires = DateTime.Now.AddDays(15)



            Dim sqluserchk1 As String = "select password from [MF-WEBUSERS] where login_email='" & username.Text & "' and isactive=0"
            conn1.Open()

            Dim userchkcmd1 As New SqlCommand(sqluserchk1, conn1)
            Dim uc1 As String = userchkcmd1.ExecuteScalar
            If uc1 <> "" Then
                Response.Redirect("~/Login/Reactiv.aspx?act=" & username.Text & " ")

            End If
            conn1.Close()

            Dim sqluserchk As String = "select password from [MF-WEBUSERS] where login_email='" & username.Text & "' and isactive=1"
            conn.Open()


            ' Response.Write(sqluserchk)
            'Response.End()

            Dim userchkcmd As New SqlCommand(sqluserchk, conn)


            Dim uc As String = userchkcmd.ExecuteScalar





            If uc <> "" Then

                If ((password.Text) = Trim(uc)) Then
                    Session("Usersess") = username.Text
                    Try
                        Dim loginuserid As String
                        Dim fname As String = ""
                        Dim lnameval As String = ""
                        Dim fullname As String = ""
                        Dim getuserinfo As String = "select * from [MF-WEBUSERS] where login_email='" & username.Text & "'"
                        Dim userinfocmd As New SqlCommand(getuserinfo, conn)
                        Dim useradp As New SqlDataAdapter()
                        Dim userds As New DataSet

                        useradp.SelectCommand = userinfocmd
                        useradp.Fill(userds)


                        If (userds.Tables(0).Rows.Count <> "0") Then
                            loginuserid = userds.Tables(0).Rows(0).Item("userid")
                            fname = userds.Tables(0).Rows(0).Item("fname")
                            lnameval = userds.Tables(0).Rows(0).Item("lname")
                            fullname = fname & " " & lnameval
                            Session("fname") = fname
                            Session("userid") = loginuserid
                            Session("fullname") = fullname

                        End If
                    Catch ex As Exception
                        Response.Write(ex.Message)
                    End Try
                    Response.Redirect("index.aspx")
                Else
                    Session("errorsess") = "NOUSER"
                    Response.Redirect("loginuser.aspx?exgpen=wer43k4jm5nhj6j6n5n4nj4&sdk4=3234jmn5bn5/5jfm6/jdfjfk\sjfj5ks&em=1&fjfjg=3eksmf\sjfijgj%jjkjfkedkdmfk%gggfd#4fgdjfkf")
                End If
            Else
                Session("errorsess") = "NOUSER"
                Response.Redirect("loginuser.aspx?exgpen=wer43k4jm5nhj6j6n5n4nj4&sdk4=3234jmn5bn5/5jfm6/jdfjfk\sjfj5ks&em=1&fjfjg=3eksmf\sjfijgj%jjkjfkedkdmfk%gggfd#4fgdjfkf")
            End If




            conn.Close()
        End If
In page load

'password.Attributes.Add("OnFocus","javascript:readCookie('"  Me.Request.Cookies "'))

Its giving error if i use above statement
can anyone help me to solve this problem
or how can i modify my code to work

Its very urgent thanks in advance