Link to home
Start Free TrialLog in
Avatar of russell12
russell12Flag for United States of America

asked on

Functions not working on new pages asp.net

I have a project and the strangest thing is happening.  I have been trying to figure it out for multiple hours.  The issue is if I create a new web form, the code behind will see all the controls, but from the .aspx page I can use any public functions from the code behind.  For example if I create the following function:

        Public Function Hey()
        Return True
    End Function

Open in new window


Then I go to the .aspx source and put the following:

    <%# hey%>

Open in new window

I get the following error: Error      2      'hey' is not declared. It may be inaccessible due to its protection level.

The following is WebForm5.aspx:

          <%@ Page Title="Web Form" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="WebForm5.aspx.vb" Inherits="InventoryManagement.WebForm5" Async="true" %>

    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <%# hey%>
        </div>
        </form>
    </body>
    </html>

Open in new window


WebForm5.aspx.vb:

    Public Class WebForm5
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
        Public Function Hey()
            Return True
        End Function
    End Class

Open in new window


I have "older" pages that I can call the exact same function from code behind. Any help would be greatly appreciated as this issue has been a problem for the last 3+ hours.  Thanks in advance!!
Avatar of Russ Suter
Russ Suter

Even though VB.Net is not case sensitive is it possible that the aspx rendering engine is? If you write "<%# Hey%>" instead does it work?

This is one of those things that I dislike about VB.Net. Even though it's not case sensitive it's a good practice to maintain a consistent case throughout your calls.
Avatar of russell12

ASKER

Russ,
Thanks for your response, but this is not the case.  In VS2013 as you type, it suggests as you know, and it doesnt suggest any function's in the behind code.  But if I add a textbox and name is txtname, and go into code behind and put on load: txtname.text = "My Name" then on page load txtname.text will = "My Name".  So it is like the code behind can see the controls on the .aspx page, but the .aspx page can not see the functions in the code behind.  If I inherit a class that has been part of the project, then it can see the functions in that class just fine.  I have tried to put a new namespace, new class and I am at a lost.  I dont know if I have a corruption somewhere that is causing this.
ASKER CERTIFIED SOLUTION
Avatar of russell12
russell12
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No one else commented on the issue.  The issue was a simple clean and rebuild.  After doing so, the aspx page could see the code behind public functions.