variable is not declared it may be inaccessible due to its protection level

后端 未结 7 873
刺人心
刺人心 2020-12-10 13:09

My VB skills are not the best, and this problem has had me stumped for a few days.

In the list of controls shown in Visual Studio that are not defined in the code be

相关标签:
7条回答
  • 2020-12-10 13:49

    I had a similar issue to this. I solved it by making all the projects within my solution target the same .NET Framework 4 Client Profile and then rebuilding the entire solution.

    0 讨论(0)
  • 2020-12-10 13:53

    Pay close attention to the first part of the error: "variable is not declared"

    Ignore the second part: "it may be inaccessible due to its protection level". It's a red herring.

    Some questions... (the answers might be in that image you posted, but I can't seem to make it larger and my eyes don't read that small of print... Any chance you can post the code in a way these older eyes can read it? Makes it hard to know the total picture. In particular I am suspicious of your Page directives.)

    We know that 1stReasonTypes is a listbox, but for some reason it seems like we don't know WHICH listbox. This is why I want to see your page directives.

    But also, how are you calling the private method FormRefresh()? It's not an event handler, which makes me wonder if you are trying to reference a listbox in a form that is not handled properly in this code behind.

    You may need to find the control 1stReasonTypes. Try maybe putting your listbox inside something like

    <div id="MyFormDiv" runat="server">.....</div>
    

    then in FormRefresh(), do a...

    Dim 1stReasonTypesNew As listbox = MyFormDiv.FindControl("1stReasonTypes")
    

    Or use an existing control, object, or page instead of a div. More info on FindControl: http://msdn.microsoft.com/en-us/library/486wc64h(v=vs.110).aspx

    But no matter how you slice it, there is something funky going here such that 1stReasonTypes doesn't know which exact listbox it's supposed to be.

    0 讨论(0)
  • 2020-12-10 13:54

    I got this error briefly after renaming the App_Code folder. Actually, I accidentally dragged the whole folder to the App_data folder. VS 2015 didn't complain it was difficult to spot what had gone wrong.

    0 讨论(0)
  • 2020-12-10 13:58

    I have found that you have to comment out the namespace wrapping the the class at time when moving between version of Visual Studio:

    'Namespace FormsAuth

    'End Namespace

    and at other times, I have to uncomment the namespace.

    This happened to me several times when other developers edited the same solution using a different version of VS and/or I moved (copied) the solution to another location

    0 讨论(0)
  • 2020-12-10 13:58

    This error occurred for me when I mistakenly added a comment following a line continuation character in VB.Net. I removed the comment and the problem went away.

    0 讨论(0)
  • 2020-12-10 14:09

    If I remember correctly, this is the default property for controls.

    Can you try by going into Design-View for the admin_reasons that contains the specified Control, then changing the control's Modifiers property to Public or Internal.

    0 讨论(0)
提交回复
热议问题