ASP.NET - Alert Username wrong and Password Wrong According field

Asked By Krishna T on 12-Jul-12 11:58 PM
Hi,

I need a requirement for login page validation. If user enter wrong username needs to alert as username wrong and if user enters password as wrong needs to alert as password wrong.  If both wrong needs to alert as Username and Password wrong?

Code Like this:

protected void Button1_Click(object sender, EventArgs e)
        {


            GetProjectDetails objbal = new GetProjectDetails();
            UserDetails[] UserDetails = null;
            UserDetails = objbal.LoginDetails(txtUsername.Text, txtPassword.Text);
            if (UserDetails == null)
            {


                lblResult.Text = "Login Not Sucess";
            }
            else
            {
                Session["UserDetails"] = UserDetails;
                lblResult.Text = "Login Sucess";
                Response.Redirect("DashBoardDSR.aspx");
            }
}

Screenshot is as follows:
Jitendra Faye replied to Krishna T on 13-Jul-12 08:52 AM
Change your code like this-

protected void Button1_Click(object sender, EventArgs e)
        {


            GetProjectDetails objbal = new GetProjectDetails();
            UserDetails[] UserDetails = null;
            UserDetails = objbal.LoginDetails(txtUsername.Text, txtPassword.Text);
            if (UserDetails == null)
            {

          Response.Write("<script>alert('Login Not Sucess')</script>");
                lblResult.Text = "Login Not Sucess";
            }
            else
            {
                Session["UserDetails"] = UserDetails;
          Response.Write("<script>alert('Login Sucess')</script>");
                lblResult.Text = "Login Sucess";
                Response.Redirect("DashBoardDSR.aspx");
            }
}
Rohan Dave replied to Krishna T on 14-Jul-12 06:41 AM
You can simple write or call javascript in your code like below.. see the bold part..

 GetProjectDetails objbal = new GetProjectDetails();
            UserDetails[] UserDetails = null;
            UserDetails = objbal.LoginDetails(txtUsername.Text, txtPassword.Text);
            if (UserDetails == null)
            {


                //lblResult.Text = "Login Not Sucess";
          Response.Write("<script> alert('Invalid User Name/Password') </script>");
      }
            else
            {
                Session["UserDetails"] = UserDetails;
                lblResult.Text = "Login Sucess";
                Response.Redirect("DashBoardDSR.aspx");
            }
Krishna T replied to Rohan Dave on 16-Jul-12 02:22 AM
Actually I need if the username wrong needs to display only username wrong?  and If the password wrong Needs to Display only Password Wrong?
Krishna T replied to Jitendra Faye on 16-Jul-12 02:22 AM
Actually I need if the username wrong needs to display only username wrong?  and If the password wrong Needs to Display only Password Wrong?
Asked By Krishna T on 16-Jul-12 02:22 AM
Actually I need if the username wrong needs to display only username wrong?  and If the password wrong Needs to Display only Password Wrong?
Rohan Dave replied to Krishna T on 16-Jul-12 02:50 AM
Then you first need to checke the "User Name" in your database.

If entered user name found in database then only check for the password. If entered user name is not found in database then write those "Response" stattement with message "UserName not found".

let me know if any thing else you require..