Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
I'm busy with a small program, but it will not build.
I get the error message:

The name 'txtGetal1' does not exist in the current context
The name 'txtGetal2' does not exist in the current context

I can not figure out what's wrong with it.
Here is my code:

namespace Week2Dag3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int getal1,getal2,som;
getal1 = Convert.ToInt16(txtgetal1.Text);
getal2 = Convert.ToInt16(txtgetal2.Text);

som = getal1 + getal2;

MessageBox.Show(Convert.ToString(som));


}
}

What do i wrong?? it little help is apricciated.
I'm just a beginner with c#

What I have tried:

Several things but i can' figure it out what is wrong with it.
Posted
Updated 14-Jun-21 1:41am

C# is case sensitive: the error refers to
The name 'txtGetal1' does not exist in the current context
The name 'txtGetal2' does not exist in the current context

but your code uses different names:
C#
getal1 = Convert.ToInt16(txtgetal1.Text);
getal2 = Convert.ToInt16(txtgetal2.Text);
 
Share this answer
 
Looks like a problem with upper/lower case of your textboxes names.

if textboxes names are 'txtGetal1' and 'txtGetal2' then you need the following code:

getal1 = Convert.ToInt16(txtGetal1.Text);
getal2 = Convert.ToInt16(txtGetal2.Text);
 
Share this answer
 
Thanks for your help, i get it running now.

namespace Week2Dag3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int Getal1,Getal2,som;
Getal1 = Convert.ToInt16(textBox1.Text);
Getal2 = Convert.ToInt16(textBox2.Text);

som = Getal1 + Getal2;

MessageBox.Show(Convert.ToString(som));


}
}
}
 
Share this answer
 
Comments
Richard MacCutchan 14-Jun-21 8:21am    
Don't use Convert.ToInt16, especially on text boxes, as any invalid data there may crash your application. Use Int16.TryParse Method (System) | Microsoft Docs[^].
The Answer is below

Issue description :
This issue usually happen when the name of the property is not available in the deign properties name 

Solution:
Step 1: Check the TextBox Name between your Design page and Code Behind

Step 2: If the Design page TextBox Name and Code Behind TextBox Name seems different then change the Code Behind TextBox Name based on the Designer Page TextBox Name.
 
Share this answer
 
Comments
Richard MacCutchan 14-Jun-21 8:22am    
OP already posted his solution.

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