0

I have a function in my ascx.vb page that i need to be called from the ascx page. However, I get an error that says its "not declared and may be inaccessible due to its protection level".

I am thinking that for some reason the functions of my ascx.vb page cant be seen from my ascx page.

I actually have this code working in aspx pages without a namespace. Anyone know what is causing this error?

The ascx.vb namespace portion reads like:

Namespace StaffLookup
    Public Class Main
        Inherits PortalModuleBase

Then the function in ascx.vb is like this:

        Public Function ProcessPictures() As String

            Return "http://info/scripts/personnel/IDVerify/BadgePictures/transparent.jpg"


    End Function

The call in ascx is like this:

<img src='<%# ProcessPictures()%>' />
drclayton
  • 63
  • 2
  • 10
  • You have changed the ancestor of the control to PortalModuleBase. What is the inheritance hierarchy for that class? Does that at some point inherit from UserControl? – Gridly Aug 05 '14 at 14:55
  • Have you tried fully qualifying it with the Namespace? – Grim Aug 05 '14 at 14:55
  • do you mean: StaffLookup.Main.ProcessPictures()? – drclayton Aug 05 '14 at 15:04
  • Yes, that is what @Grim meant. Also, What does the Control tag look like in the .ascx files, specifically the CodeFile and Inherits attributes? – Gridly Aug 05 '14 at 15:21
  • ok so when i do StaffLookup.Main.ProcessPictures() it has an error that says "ProcessPictures is not a member of Stafflookup.Main". Also, the control tag looks like: <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="Main.ascx.vb" Inherits="StaffLookup.Main" %> – drclayton Aug 05 '14 at 16:46
  • Your function has a ramdom **End If** statement in it. Is that there when yoiu are compiling it? If the error message displayed during compaile or when the page is displayed? – Gridly Aug 05 '14 at 19:32
  • oh sorry disregard the end if. I meant to take that out. I condensed the bits inside the function to avoid posting a lot of code. The error displays during compile. Its an error with a red line etc. – drclayton Aug 05 '14 at 19:42

2 Answers2

0

The only way I have been able to reproduce this error is if there is a second class with the same namespace, class name and method name where the second method has private scope.

The compiler is merging these two classes and the private version of the method ends up being the one used, so you end up with the error you are seeing. There will be warning messages on the class name and method name.

Check your code to see if you have another class with this same namespace and class name, and then see if it has a method with the same signature.

Also check the parent classes up the inheritance chain starting with PortalModuleBase. You can stop looking once you get to UserControl.

Like this:

Namespace StaffLookup
    Public Class Main
        Inherits PortalModuleBase

        Public Function ProcessPictures() As String

            Return "http://info/scripts/personnel/IDVerify/BadgePictures/transparent.jpg"

        End Function

    End Class
End Namespace

Namespace StaffLookup

    Public Class Main
        Private Function ProcessPictures() As String

            Return "http://info/scripts/personnel/IDVerify/BadgePictures/transparent.jpg"

        End Function

    End Class

End Namespace
Gridly
  • 938
  • 11
  • 13
  • I've looked up and down and see no duplicate namespaces/classes etc. I am going to create a new project with completely different naming and see if it was just some sort of "corrupt" project i had going on. – drclayton Aug 06 '14 at 12:23
  • ive discovered that if I create an "empty web site" the error doesnt happen and it works fine. However, if I create an "empty web application" the error exists. What could cause that? – drclayton Aug 06 '14 at 18:50
0

Come to find out, the answer is here:

Asp.net controls are not accessible in code behind

Even when creating a brand new empty application you have to right click and choose convert to web app. This worked for me

Community
  • 1
  • 1
drclayton
  • 63
  • 2
  • 10