locked
App_Code RRS feed

  • Question

  • User-2139027374 posted

    Hi,

    I have created a simple project (website) using asp.net. The project has a default page (Default.aspx) and a class (Class1.cs). Class1.cs resides inside a folder called App_Code.

    The Default.aspx page has a button and a label. On a click of the button, I'd like to populate the label with a text of "hello world".

    The text (hello world) is comming from a method called "foo" which resides in Class1.cs.

    When I run it locally (http://localhost:8080/Default.aspx), it works fine. But, when I upload it to the webserver, and run it from browser, it doesn't work.

    Here is the error message generated from the server: The name 'Class1' does not exist in the current context

    My code:

    protected void Button1_Click(object sender, EventArgs e)
    {
    Label1.Text = Class1.foo();
    }
    
    public static string foo()
    {
    return "hello world";
    }
    



    Please help!

    thanks

    Monday, October 23, 2017 6:16 PM

All replies

  • User-1838255255 posted

    Hi Dzung,

    According to your description and code, i make a test in my side(server side and localhost), i found it works. Here is my test code, please check: 

    Sample Code:

    Test.aspx:
     <div>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1" />
     </div> 
    Test.aspx.cs:
     protected void Button1_Click1(object sender, EventArgs e)
            {
                Label1.Text = TestClass.foo();
            }
    
    TestClass:
    public class TestClass
        {
            public static string foo()
            {
                return "hello world";
            }
        }

    Result:

    So please check if you miss the DLL(class) when your publish it to the IIS?  Please check the following tutorial: 

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/a66c02a5-6342-4f0c-8b4f-ea98eae0c00a/dll-reference-files-missing-after-publish-into-iis?forum=wcf 

     

    Best Regards,

    Eric Du 

    Wednesday, October 25, 2017 2:33 AM