Last post Sep 09, 2010 02:17 AM by CHVincent
Sep 14, 2006 05:45 AM|Jason Duncan|LINK
I have two identical dropDownLists (DropDownList1 and DropDownList2) on an aspx form. When I compile, I get a:
Error 1 The name 'DropDownList2' does not exist in the current context C:\websites\mdFrontEnd\Location.aspx.cs 48 17 C:\websites\mdFrontEnd\
The error occurs in my behind code (aspx.cs) file. However, I can clearly reference both DropDownLists in the aspx.cs because Intellisense recognizes them as existing. The Location.aspx and Location.aspx.cs do appear to inherit properly:
Location.aspx.cs code block:
protected void Button1_Click(object sender, EventArgs e)
string val1 = DropDownList1.Text; // OK
string val2 = DropDownList2.Text; // Errors on compile
Any ideas would be greatly appreciated.
Sep 14, 2006 08:36 AM|Jasson_King|LINK
Sep 14, 2006 08:39 AM|Dragon.X.Dragon|LINK
could you elaborate how do you declare the ddl1 and ddl2 ?
Sep 14, 2006 01:21 PM|Jason Duncan|LINK
Thank you for your help. The problem that was causing this was the following:
1. There were two forms in my website project that were using the same partial class name. How did this happen? Earlier in the evening I had made a backup copy of the Location.aspx form and named it Location2.aspx.
2. This was causing a conflict because I never changed the Location2.aspx partial class name. Therefore: Location.aspx.cs and Location2.aspx.cs were both:
class Location : System.Web.UI.Page
3. So my Location.aspx partial class was using the Location2.aspx partial class code and NOT the Location.aspx.
4. Excluded Location2.aspx and that solved the problem.
Dec 15, 2006 07:24 PM|JimAmigo|LINK
I haven't made a copy of my webform and codebehind file and still get a similar error.
I have a frormview with a couple of dropdownlists. I found this example code and after modifying it for my file get the similar error. The name dll does not exist in in the current context.
My only guess is that the orginial code example doesn't use a code behind file where I am using a .cs file?
Here is the code that is causing the error..
protected void ddl_Contractors_DataBound(object sender, EventArgs e)
DropDownList ddl = (DropDownList)sender;
//add an empty item on top of the list
FormView frmV = dll.NamingContainer;
if (frmV.DataItem != null)
//Let's pull the contractor value from the databound item. The data
//in my application is supplied by BLL as a dataview. Therefore each
//item bound to the FormView is of type DataRowView. So let's cast
//that DataItem to the appropriate type to be able to use it
string strcontractorID = ((DataRowView)frmV.DataItem)["contractorID"].ToString();
//be careful of the possibility that the value saved on the
//database does not exist in the valid selections that are displayed
//on the list
ListItem li = ddl.Items.FindByValue(strcontractorID);
if (li != null) li.Selected = true;
//since the JobTitles selection is dependent on the contractorID, we
//have to databind the JobTitles list after we changed the selection for the ContractorID
ddl = (DropDownList)frmV.FindControl("ddl_JobTitles");
if (ddl != null) ddl.DataBind();
Here is the website with the original example.http://www.webswapp.com/codesamples/viewsource.aspx?file=~/codesamples/aspnet20/dependentlists/default.aspx
Apr 23, 2008 06:44 PM|heitoralthmann|LINK
Take a look at you aspx.designer.cs file ;)
If, there's no problem over there, try it:
The name does not exist in the current context asp.net error
Apr 12, 2009 01:33 PM|Abdul Quader Mamun|LINK
Sep 09, 2010 02:17 AM|CHVincent|LINK
This bother me a lot!!! for a long~~~ time!!!
Well~ THANKS!! I solve it with your solution, Great!
I love you guys~!
beginner... compared to all you..