Many a times while writing a code we get this error which says, “The name <control> does not exists in the current context”. This is because the code behind file is not able to find the control being added to your aspx file.
There are three possible solutions for this error,
1 – There are two classes with same name. Possibly you have renamed a page and created a new one, but you did not changed the name in the cs file. So make sure you have only one file with this name in your project. There may be two files with different name but same class name this may create problems.
2 – Multiple web.config files in your project. Make sure you have only one web.config file in your project. However you can have mulitple web.config files in your project but that has to be in particular format check here.
3 – The designer file is not refreshed.
In this case you have to delete the existing designer file
After deleting the file right click on the page, in this case default.aspx and select “Convert to web application”
Once you convert it will prompt for confirmation just select yes
Once converted you can see the added control declaration in the designer file.
Now you can use the control in your code behind.
Enjoy coding 🙂