How to access html controls in code behind

后端 未结 3 1314
一向
一向 2020-12-17 16:05

I\'m trying to follow this example on how to validate credentials. However, it uses asp: controls for the login form.

If I were to use html controls instead so CSS s

3条回答
  •  温柔的废话
    2020-12-17 16:58

    Add id and runat server attributes to the input tag (see below)

    
    
    

    You also need to change Text to Value in your code:

    protected void LoginButton_Click(object sender, EventArgs e)
    {
        // Validate the user against the Membership framework user store
        if (Membership.ValidateUser(Username.Value, Password.Value))
        {
            // Log the user into the site
            FormsAuthentication.RedirectFromLoginPage(UserName.Value, RememberMe.Checked);
        }
        // If we reach here, the user's credentials were invalid
        InvalidCredentialsMessage.Visible = true;
    }
    

    You can also add a html checkbox for RememberMe

    
    

    Now you can check the checked states by calling RememberMe.Checked

提交回复
热议问题