Search code examples
c#asp.netinline-code

Compilation error - inline code


I'm using a 3-tier architecture for my application. I'm using inline code to call certain methods found in the business logic. I have a method which returns a particular string message. The following code is returning an error

<div id="logo">
<h1><a href="/" title='<%= systemMessagesBL.ReturnMessage("MSG_MAINPAGE_TOOLTIP", 1) %>'>Application</a></h1>
</div>

The error being: CS0103: The name 'systemMessagesBL' does not exist in the current context. And this although I already made a reference to it using the following embedded code:

<% BusinessLogic.SystemMessagesBL systemMessagesBL = new BusinessLogic.SystemMessagesBL(); %>

What may be the problem?


Solution

  • Try declaring your object in a code-behind file, not inline, and make it protected:

    protected BusinessLogic.SystemMessagesBL systemMessagesBL = 
       new BusinessLogic.SystemMessagesBL();
    

    then your inline stuff should pick it up.