You're not passing in an argument to Membership.GetUser();
Membership.GetUser();
Gets the currently-logged in user. As you're not logged in it will return null
. If you were logged in it would return only you, and not your members.
If you want to get the user then you need to pass in their username
. Like this:
MembershipUser u = Membership.GetUser(TextBox1.Text);
UPDATE
You don't need to do a call to the SQL Database to check if the user exists.
you can do this instead.
MembershipUser u = Membership.GetUser(TextBox1.Text);
if (u != null){
SendMail();
u.ChangePassword(u.ResetPassword(), code);
}else{
lab_Message.Visible = true;
lab_Message.Text = "This username is invalid.";
lab_Message.ForeColor = System.Drawing.Color.Red;
}
By the way, the users password will NOT be set to code
- this will get set to the users answer to their security question. ResetPassword
resets the password to an automatically generated one.
See here for documentation. http://msdn.microsoft.com/en-us/library/system.web.security.membershipuser.resetpassword.aspx