I encountered an error. Despite declaring the variables (failturetext and userName) errors still appear. Can anyone please help me?
- Use of Unassigned local va
Regarding the compiler message - look at this link
TextBox FailureText; - you declared a variable, but it is not initialized. you might set it to null / a value / default() - but you must initialize it
TextBox UserName; - the same
when you call UserName.Text - the compiler alerts for the uninitialized UserName
If you wish to keep the same convention as you have at the moment, then to solve the issue of it failing compilation you want to assign the two variables a null value first before you try to reference them.
Like so:
TextBox FailureText = null;
TextBox UserName = null;
If you do this, you might need to check on whether they are still null when you try and assign the properties of these objects.
As people above have stated, you should not be doing it this way as UI controls should always be global to the form itself.
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.