locked
Name does not exist in this context (but it does!) RRS feed

  • Question

  • User977421240 posted

    Or at least I think it does!

    Here is what I have. I am working with VS2015 .Net 4.6.1.  Working on a C# web forms site. One page is kicking my tail bad. 

    I have a FormView sitting in my aspx page bound to sqldatasource. This result in the auto-generation of:

     protected global::System.Web.UI.WebControls.FormView ChangeFormFV;

    ... in the related sub design.cs file (it isn't commented out).

    So I am puzzled why it is that in my aspx.cs file where this code exists:

    Panel control = ChangeFormFV.Row.FindControl("ShortDescPnl") as Panel;
        if (control != null)
            control.Visible = true;

    ... Do I get redlined on ChangeFormFV indicating that The name 'ChangeFormFV' does not exist in the current context?'

    I've gone back to review what is included regarding References on my project and I don't see anything that jumps out at me that might be missing. Here is what I have in References for the project:

    Analyzers
    AntIr3.Runtime
    AspNet.ScriptManager.bootstrap
    AspNet.ScriptManager.jQuery
    CsvHelper
    EntityFramework
    EntityFrameworkSeeder.EF6
    EntityFramework.SqlServer
    Microsoft.AI.Agent.Intercept
    Microsoft.AI.DependencyCollector
    Microsoft.AI.PerfCounterCol lector
    Microsoft.AI.ServerTelemetryChannel
    Microsoft.AI.Web
    Microsoft.Ai.WindowsServer
    MicrosoftApplicationlnsights
    Microsoft.AspNet.EntityDataSource
    Microsoft.AspNet.FriendlyUrls
    Microsoft.AspNet.Web.Optimization.WebForms
    Microsoft.CodeDom.Providers.DotNetCompilerPlatform
    Microsoft.CSharp
    Microsoft.ScriptManager.MSAJax
    Microsoft.ScriptManager.WebForms
    Microsoft.Web.Infrastructure
    Newtonsoft.Json
    System
    System.ComponentModel.DataAnnotations
    System.Configuration
    SystemCore
    System.Data
    SystemData.DataSetExtensions
    System.Drawing
    SystemEnterpriseServices
    System.Runtime.Serialization
    System.Security
    System.Web
    System.Web.AppI icationServices
    System.Web.DynamicData
    SystemWeb.Entity
    System.Web.Extensions
    System.WebHelpers
    System.WebMvc
    System.Web.Optimization
    System.Web.Razor
    System.Web.Services
    System.Web.WebPages
    System.Web.WebPages.Deployment
    System.Web.WebPages.Razor
    System.Windows.Forms
    System.XmI
    System.XmI.Linq
    WebGrease
    

    So I am at a loss.  I think my code has some issues that I need to fix after getting past this but need to resolve this issue first.  Trying to set the visibility attribute of a panel inside of a FV and I have to do it in code behind.  Only other way I could figure to do it would be with a variable for each of the target panels that I manipulated from the code behind.. I played with that concept a bit and got no where fast.

    Any thoughts would be greatly appreciated!

    Wednesday, August 17, 2016 8:13 PM

Answers

  • User303363814 posted

    Two things

    1) Sometimes the build system can get out of step with the state of files.  Have you tried right clicking on the solution and select 'clean solution', then build again?

    2) Always, always, always deal with the first error that is reported.  Not the most interesting one or the last one or some random one.  If there is a problem which is causing the generated code to not be compiled then your code-behind page will not find some/all of the things declared in the uncompiled generated page.

    If neither of these give any joy then it can sometimes be best to just recreate the page.  That is, add a new page and build it again.  If you are mega-cautious then you can add a control, reference it in the code-behind and then compile (ctrl-shift-b is useful).  Repeat until done or a problem turns up.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 17, 2016 9:55 PM

All replies

  • User303363814 posted

    Two things

    1) Sometimes the build system can get out of step with the state of files.  Have you tried right clicking on the solution and select 'clean solution', then build again?

    2) Always, always, always deal with the first error that is reported.  Not the most interesting one or the last one or some random one.  If there is a problem which is causing the generated code to not be compiled then your code-behind page will not find some/all of the things declared in the uncompiled generated page.

    If neither of these give any joy then it can sometimes be best to just recreate the page.  That is, add a new page and build it again.  If you are mega-cautious then you can add a control, reference it in the code-behind and then compile (ctrl-shift-b is useful).  Repeat until done or a problem turns up.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 17, 2016 9:55 PM
  • User977421240 posted

    Paul,

    Thanks for the rebuilding of the page tip... That just saved my sanity.  I was fairly sure I was doing everything right but was going crazy!  I created a new page with a slightly different name then copy and pasted the aspx content from the original to the new one.  Then checked the design.cs to make sure that the global had been established as it should have for the FormView.  After that I proceed rebuild the aspx.cs to where it was and wahah!! NO ERROR!

    Thanks!

    Thursday, August 18, 2016 12:54 PM