asp.Net does not exist in current context

后端 未结 10 1802
夕颜
夕颜 2021-02-07 08:39

I am facing a small big problem. I have taken a dropdownList control and ID is \"drpDownCountries\" in ASP.Net project. The problem is that \"The dropdownlist contr

相关标签:
10条回答
  • 2021-02-07 09:42

    I had this same problem and tried all the answers listed here, to no avail.

    What finally worked for me was to make a change to the ascx file in Design view and then save it. This finally forced Visual Studio to regenerate the designer.cs file and include my new control.

    0 讨论(0)
  • 2021-02-07 09:43

    Do not let Intellisense fool you. Sometimes (usually after fixing problems with duplicate class names), you simply need to rebuild the project and the reported errors go away. Reopening the file after the build might be necessary.

    0 讨论(0)
  • 2021-02-07 09:46

    I have seen this error occur when there is a copy of the .aspx page in the project folder.

    Example:

    Error occurs in Test.aspx.

    There is a Test-copy.aspx file in the project folder.

    Delete, rename with a different extension, or move Test-copy.aspx to a different folder.

    Error is resolved.

    0 讨论(0)
  • 2021-02-07 09:46

    You should put some code to get help..

    Anyway, the problem could be that drpDownCountries is contained within a Panel control.

    The Panel control is a Container control, in that it can hold lots of controls.
    In order to access the controls within that Panel control, you first need to "help" ASP.Net to find it.

    The typical way of doing this is to use the FindControl method look here.

    Code sample:

    DropDownList myDrop = (DropDownList)this.Panel1.FindControl("drpDownCountries");
     if(myDrop != null)
      {
         ..somecode..
      }
    
    0 讨论(0)
提交回复
热议问题