文本框明确问题

时间:2013-11-29 03:29:57

标签: c# visual-studio-2012 login

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

 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.";
            }
        }
    }       

2 个答案:

答案 0 :(得分:2)

当您的页面加载时,将运行以下脚本。在LogIn表单中包含脚本文件 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>

答案 1 :(得分:-1)

还有其他方法,这是其中之一

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