I encountered an error. Despite declaring the variables (failturetext and userName) errors still appear. Can anyone please help me?
- Use of Unassigned local variable "FailureText"
- Use of Unassigned local variable "UserName"
protected void Login1_LoginError(object sender, System.EventArgs e)
{
TextBox FailureText;
TextBox UserName;
//There was a problem logging in the user
//See if this user exists in the database
MembershipUser userInfo = Membership.GetUser(UserName.Text); // errors appear here
if (userInfo == null)
{
//The user entered an invalid username...
//error appear here ( failuretext.text)
FailureText.Text = "There is no user in the database with the username " + UserName.Text;
}
Thanks (:
You’ve declared the variables, but you haven’t assigned anything to them before you are attempting to reference their properties. That’s the origin of the messages. You’ve got bigger problems, though, because those represent UI controls and it’s highly unlikely that they should be local variables in your function. They probably ought to belong to the page (or form) rather than be declared locally.