I have a Windows Form application with a button named loginBtn and a label called loginMessageLbl on my form.
Now when I write the following piece of code it gives me an error sayin “The name ‘loginMessageLbl’ does not exist in current context”.
I am not sure how do I change the text value of the label once I click on the button:
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void loginBtn_Click(object sender, EventArgs e)
{
loginMessageLbl.text = "Invalid Username or password";
}
}
}
Intellisense should tell you if it exists when you typed it out – it would also help you if you’ve got the name slightly wrong or capitalisation is different. Also, you’re trying to set a property called “text” – the property you actually want is “Text” with a capital T.