Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. newbie question - asp.net & javascript

newbie question - asp.net & javascript

Scheduled Pinned Locked Moved ASP.NET
questioncsharpjavascriptasp-net
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lior Shoval
    wrote on last edited by
    #1

    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.

    D T 2 Replies Last reply
    0
    • L Lior Shoval

      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.

      D Offline
      D Offline
      DavidNohejl
      wrote on last edited by
      #2

      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.)

      1 Reply Last reply
      0
      • L Lior Shoval

        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.

        T Offline
        T Offline
        Tomas Petricek
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups