Reputation: 1
Ok im having a problem with the text boxes of my page holding values of the login info when i navigate to the start up page via the back button of the browser. i need the text boxes to clear when the page is loaded but when i use the code im using the text boxes stay equal to "" instead of the user input when the login button is clicked. heres my code.
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.";
}
}
}
Upvotes: 0
Views: 177
Reputation: 320
When ever your page is loaded the following script will run.Include script file jquery-1.4.1.js in your LogIn form it will work even when you click Browser Back Button.
<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>
Upvotes: 2
Reputation: 1458
there are other ways, this is one of them
protected void btnLogin_Click(object sender, EventArgs e)
{
// rest of your code
txtEmailLog.Text = "";
txtPasswordLog.Text = "";
}
Upvotes: -1