Web site vs Web Project: scope difference?


O

olduncleamos

Hi all,

I am running into the following problem that I am just plain stuck.
Can't even find a starting point to look:

I originally had a "web site" created in VS2005. Within the site I
have a helper class (under the App_code directory) called PageHelper.
Within the class there are a bunch of static functions.

On most of the pages, I will have something like the following on the
HTML side:
<a href="<%# PageHelper.GetLocation() %>'>....

Now I am starting a Web Application project in VS2005 and thought I
would do something similar. But the above line is now giving me a
stubborn problem. The application will compile fine, but when I hit
the page, I will get an error message:
CS0103: The name 'PageHelper' does not exist in the current context

The code behind file have no problem calling the PageHelper class but
the inline code can't seem to see it. I have checked to make sure the
namespace is identical.

Any help will be greatly appreciated. I plain can't see a direction to
this problem.

Thanks in advance.
 
Ad

Advertisements

A

Alexey Smirnov

Hi all,

I am running into the following problem that I am just plain stuck.
Can't even find a starting point to look:

I originally had a "web site" created in VS2005. Within the site I
have a helper class (under the App_code directory) called PageHelper.
Within the class there are a bunch of static functions.

On most of the pages, I will have something like the following on the
HTML side:
<a href="<%# PageHelper.GetLocation() %>'>....

Now I am starting a Web Application project in VS2005 and thought I
would do something similar. But the above line is now giving me a
stubborn problem. The application will compile fine, but when I hit
the page, I will get an error message:
CS0103: The name 'PageHelper' does not exist in the current context

The code behind file have no problem calling the PageHelper class but
the inline code can't seem to see it. I have checked to make sure the
namespace is identical.

Any help will be greatly appreciated. I plain can't see a direction to
this problem.

Thanks in advance.

Maybe you need to define the namespace

Either try to add

<%@ Import Namespace="NSHERE" %>

or

<a href="<%# NSHERE.PageHelper.GetLocation() %>'>

Hope this helps
 
O

olduncleamos

Maybe you need to define the namespace

Either try to add

<%@ Import Namespace="NSHERE" %>

or

<a href="<%# NSHERE.PageHelper.GetLocation() %>'>

Hope this helps- Hide quoted text -

Thanks so much! I added the <%@ Import Namespace... %> and it is
working now. I tried to full qualify the PageHelper class as you
suggested in the second option but that didn't work. Besides the page
class and the helper class are in the same namespace. I must be
missing something here.

Thanks again for your help.
 
M

Mark Fitzpatrick

The actual page designer surface though is not in the namespace you think it
is. It's expected to be in the same namespace and class as the codebehind is
since it's a partial class after all, but that's not exactly the case. You
may notice in some of the runtime errors that you'll see a different
classname that has the aspnet phrase in it. In other words, these other
calls tend to run within their own space.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
Ad

Advertisements

A

Alexey Smirnov

Thanks so much! I added the <%@ Import Namespace... %> and it is
working now. I tried to full qualify the PageHelper class as you
suggested in the second option but that didn't work. Besides the page
class and the helper class are in the same namespace. I must be
missing something here.

Thanks again for your help.- Hide quoted text -

- Show quoted text -

BTW, the right syntax is

<a href="<%= NSHERE.PageHelper.GetLocation() %>">

"<%=" equals to Response.Write and href must be closed with ( " )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top