文本框清除问题

本文关键字:问题 清除 文本 | 更新日期: 2024-05-25 16:08:32

好的,当我通过浏览器的后退按钮导航到启动页面时,我的页面中包含登录信息值的文本框出现问题。我需要在加载页面时清除文本框,但当我使用代码im时,使用的文本框保持等于",而不是单击登录按钮时的用户输入。这是我的密码。

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack == true)
        {
            txtEmailLog.Text = "";
            txtPasswordLog.Text = "";
        }
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        PlayerModel plyrModel = new PlayerModel();
        PlayerBLO plyrBLO = new PlayerBLO();
        List<PlayerModel> models = plyrBLO.GetAllPlayers();            
         foreach (PlayerModel player in models)
        {
            if (txtEmailLog.Text == player.PlayerEmail && txtPasswordLog.Text == player.PlayerPassword)
            {
                Session.Add("Player", player);
                Response.Redirect("PlayerMenu.aspx");
            }
            else
            {
                lblMessage.Text = "Invalid Login! Retry or Register.";
            }
        }
    }       

文本框清除问题

加载页面时,将运行以下脚本。在登录表单中包含脚本文件jquery-1.4.1.js,即使单击"浏览器返回"按钮,它也能工作。

<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        // clear the text box values onload.
        $('#<%=txtEmailLog.ClientID%>').val('');
        $('#<%=txtPasswordLog.ClientID%>').val('')
    });
</script>

还有其他方法,这是

protected void btnLogin_Click(object sender, EventArgs e)
{
   // rest of your code
      txtEmailLog.Text = "";
      txtPasswordLog.Text = "";
}