Skip to content
Loading
  • +2
    i am ot facing any error... i want to show if username is incorrect then show username is incorrect and if password is incorrect then show password is incorrect
    +2
  • +2
    This is working code.
      
    Thanx once again  Varun Setia...
     
    protected void Button1_Click(object sender, EventArgs e)
    {
    using (var context = new WallpaperEntities4())
    {
    string UserName = Convert.ToString(Session["UserName"]);
    User user = (from c in context.Users
    where c.UserName == TxtUserName.Text
    select c).FirstOrDefault();
    if (user == null)
    {
    LblMesge.Text = "Invalid Username";
    }
    else if (!user.Password.Equals(TxtPassword.Text))
    {
    LblMesge.Text = "Invalid Password";
    }
    else
    {
    WallpaperEntities4 db = new WallpaperEntities4();
    string ID = Request.QueryString["Id"];
    Session["UserName"] = UserName;
    Response.Redirect("/Walpaper.aspx?username=" + UserName);
    }
    }
    +2
  • Jenith Thakkar
    +1
    What kind of error you're facing with above code?
    +1
  • Varun Setia
    +1
    1. bool usernameExists = (from c in db.Users  
    2. where c.UserName == TxtUserName.Text  
    3. select c).Count() >0;  
    4.    
    5. if(usernameExists){  
    6. string UserName = TxtUserName.Text;  
    7. WallpaperEntities4 db = new WallpaperEntities4();  
    8. string ID = Request.QueryString["Id"];  
    9. string query = (from c in db.Users  
    10. where c.UserName == TxtUserName.Text && c.Password == TxtPassword.Text  
    11. select c.UserName).FirstOrDefault();  
    12. if (query != null)  
    13. {  
    14. Session["UserName"] = UserName;  
    15. Response.Redirect("/Walpaper.aspx?username="+UserName);  
    16. }  
    17. else  
    18. LblMesge.Text = "Invalid password";  
    19. }  
    20.   
    21.    
    22.    
    23. }else{  
    24.  //No username exists logic  
    25. LblMesge.Text = "Invalid User";

    26. }   
    Try this :)
    +1
  • +1
    hi 
    Varun
     
    cant i put in if else condition.... 
    +1