newbie question - asp.net & javascript
-
Hi. I'm new to asp.net and i have a question: let's say i have a login page. in the page i have a label which is supposed to show the client how many times he's attempted to login. I have several text controls to allow the client enter his username & etc... each control has a validator control and finally a submit button. like the validators control don't postback (by default), i'd like to count the times the client tries to login on the client side - meaning i have to have a javascript function. I've added the submit button onclick event using: this.loginBtn.attributes.add("onclick","cClick();"); the function get's called, and what i tried to do in it was something like: function cClick() { var num=document.getElementById("lblNumber"); var iNum=num.value; iNum++; num.value=iNum; } but it doesn't do anything. what's wrong here ? Thanks, Lior.
-
Hi. I'm new to asp.net and i have a question: let's say i have a login page. in the page i have a label which is supposed to show the client how many times he's attempted to login. I have several text controls to allow the client enter his username & etc... each control has a validator control and finally a submit button. like the validators control don't postback (by default), i'd like to count the times the client tries to login on the client side - meaning i have to have a javascript function. I've added the submit button onclick event using: this.loginBtn.attributes.add("onclick","cClick();"); the function get's called, and what i tried to do in it was something like: function cClick() { var num=document.getElementById("lblNumber"); var iNum=num.value; iNum++; num.value=iNum; } but it doesn't do anything. what's wrong here ? Thanks, Lior.
look at generated code, it usually helps. Plus check it with JavaScript console (in Firefox) or whatever. this is how I debug JS. :) best regards, David 'DNH' Nohejl Never forget: "Stay kul and happy" (I.A.)
-
Hi. I'm new to asp.net and i have a question: let's say i have a login page. in the page i have a label which is supposed to show the client how many times he's attempted to login. I have several text controls to allow the client enter his username & etc... each control has a validator control and finally a submit button. like the validators control don't postback (by default), i'd like to count the times the client tries to login on the client side - meaning i have to have a javascript function. I've added the submit button onclick event using: this.loginBtn.attributes.add("onclick","cClick();"); the function get's called, and what i tried to do in it was something like: function cClick() { var num=document.getElementById("lblNumber"); var iNum=num.value; iNum++; num.value=iNum; } but it doesn't do anything. what's wrong here ? Thanks, Lior.
Hi, I think, that it is not possible to count number of tries on client side, because you can't check if login information is correct on client side. You need postback to do this. I think, that better idea is to store number of tries on server side using Session or maybe ViewState, but I'd prefer Session, because it is more secure (unless you are using ViewState encryption). But if you want to prevent user (Hacker?) from trying to login more than three times you should save number of tries in database associated with his IP adress, because if you store this in Session it is not problem to open new browser window and try anotrher three passwords...
// code in event handler on server side (asp.net)
int tries=0;
if (Session["logintries"]!=null) tries=(int)Session["logintries"];
if (tries<3)
{
// check password...
if (invalidPassword) tries++;
}
else
{
labelError.Text="No no no..";
}
Session["logintries"]=tries;Tomáš Petříček (Microsoft C# MVP)
www.eeeksoft.net | Asp.Net Graphical controls