1

When I call static method from asp page I got this Compilation Error:

CS0103: The name 'Tudo' does not exist in the current context 
Line 10: <script src="<%= Tudo.getFromDefinicao("winJS") %>" type="text/javascript"></script>

Tudo is a static class which is in App_Code paste, and the namespace is the same of my asp pages.

namespace MySite
{
   public static class Tudo
   {
     public static string getFromDefinicao(string key)
     {
        //do some stuff
        return myString;
     }
   }
}

I want call getFromDefinicao(...) method from my asp, but asp don't find the class (in this case i'm calling in my MasterPage). If I call the methods inside Tudo.cs from MasterPage.cs I have no problem, and I don't need to declare "using 'namespace';" because they are in the same namespace...

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs" Inherits="MySite.MasterPage" %>
<html>
<head>
 <script src="<%= Tudo.getFromDefinicao("winJS") %>" type="text/javascript"></script>
</head>
.......

What I have to do to solve this?

2 Answers 2

2

try to add the namespace MySite

<script src="<%= MySite.Tudo.getFromDefinicao("winJS") %>
Sign up to request clarification or add additional context in comments.

2 Comments

I got this error: Compiler Error Message: CS0433: The type 'MySite.Tudo' exists in both 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\e22c2559\92c7e946\assembly\dl3\15b7a136\b0ad4c8e_c9e8cd01\MySite.DLL' and 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\e22c2559\92c7e946\App_Code.-jcciwpl.dll'
probably you have an ambiguous class method. Try to change the namespace or remove the other method
1

Solution: add the namespace when calling the method:

<script src="<%= MyNamespace.MyStaticClass.myMethod()

If appears this error:

Compiler Error Message: CS0433: The type 'MySite.Tudo' exists in both 'C:...' and 'c:..'

Remove the class from ASP.NET Folder App_Code to another one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.