Click here to Skip to main content
15,911,848 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir,

I create a web method for login page this is my code
C#
[WebMethod]
    public bool Login(string user , string pass)
    {
       pass ="TxtPassword.Text";
        user ="TxtUserName.Text";
        string username = "Login";
  string   Password = "Login";
        if (user == username && pass == Password)
        {
            return true;
        }
        else
        {
            return false;
        }

    }
}


But this not working.

Please give me solution
Thanks in Advance.

Arvind kumar singh
Posted
Updated 13-Jul-11 3:44am
v2

Remove the quotes and use this.
C#
pass = TxtPassword.Text;
user = TxtUserName.Text;
 
Share this answer
 
A WebMethod must be marked as 'Static':


C#
[WebMethod]
public static bool Login(string user , string pass)
{
    pass ="TxtPassword.Text";
    user ="TxtUserName.Text";
    string username = "Login";
    string Password = "Login";
    if (user == username && pass == Password)
    {
        return true;
    }
    else
    {
        return false;
    }
}
 
Share this answer
 
Comments
RaviRanjanKr 13-Jul-11 9:33am    
5+
Don't forget that you should be using

return (user.Equals(userName) && pass.Equals(Password));

rather than
return (user == username && pass == Password);
 
Share this answer
 
Comments
R. Giskard Reventlov 13-Jul-11 9:32am    
http://blogs.msdn.com/b/csharpfaq/archive/2004/03/29/when-should-i-use-and-when-should-i-use-equals.aspx
RaviRanjanKr 13-Jul-11 9:33am    
5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900