I’m trying to use the password recovery using vb. I found the c# code online and am trying to convert it to vb. I’m getting “end of statement expected” error. Can anybody see the issue?
c# code:
protected void validateUserEmail(object sender, LoginCancelEventArgs e)
{
TextBox EmailAddressTB =
((TextBox)PWRecovery.UserNameTemplateContainer.FindControl("EmailAddressTB"));
Literal ErrorLiteral =
((Literal)PWRecovery.UserNameTemplateContainer.FindControl("ErrorLiteral"));
MembershipUser mu = Membership.GetUser(PWRecovery.UserName);
if (mu != null) // The username exists
{
if (mu.Email.Equals(EmailAddressTB.Text)) // Their email matches
{
ProfileCommon newProfile = Profile.GetProfile(PWRecovery.UserName);
HttpCookie appCookie = new HttpCookie("usernameCookie");
appCookie.Value = newProfile.FullName;
appCookie.Expires = DateTime.Now.AddMinutes(3);
Response.Cookies.Add(appCookie);
}
else
{
e.Cancel = true;
ErrorLiteral.Text = "Your username and password do not match";
}
}
else
{
e.Cancel = true;
ErrorLiteral.Text = "No such user found.";
}
}
vb code:
Protected Sub SubmitButton_Click(sender As Object, e As System.EventArgs)
Dim user As MembershipUser = Membership.GetUser(PasswordRecovery1.UserName)
Dim errorLiteral As Literal = (Literal)PasswordRecovery1.UserNameTemplateContainer.FindControl("FailureText")
If (user IsNot Nothing) Then
Dim password As String = user.GetPassword()
EmailPassword(user.Email, password, user.ToString())
Else
errorLiteral.Text = "No such user found."
End If
End Sub
can be just
If you’d prefer, you can also use Ctype(object, type) or DirectCast(object, type) – example: