1

vbを使用してパスワード回復を使用しようとしています。私はオンラインでc#コードを見つけ、それをvbに変換しようとしています。「ステートメントの終わりが必要です」というエラーが発生します。誰かが問題を見ることができますか?

c#コード:

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コード:

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
4

1 に答える 1

2
Dim errorLiteral As Literal = (Literal)PasswordRecovery1.UserNameTemplateContainer.FindControl("FailureText")

ただすることができます

Dim errorLiteral As Literal = PasswordRecovery1.UserNameTemplateContainer.FindControl("FailureText")

必要に応じて、Ctype(object, type) または DirectCast(object, type) を使用することもできます - 例:

Dim errorLiteral As Literal = CType(PasswordRecovery1.UserNameTemplateContainer.FindControl("FailureText"), Literal)
于 2012-08-27T21:54:09.840 に答える