Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
0) When I create a class, the App_Code folder isn't automagically created for me.

1) I've written a BasePage class that inherits from System.Web.UI.Page. When I type that out, intellisense doesn't change the color of Page like I'm used to (but it's not underlinedeither to indicate an error).

2) When I try to use the BasePage class elsewhere in the site, it says it can't find it when I try to view a page in the browser.

Is this all happening because I'm doing a web app versus a web site? If so, how can I fix it? I've tried moving the base page class to the root site folder, and that didn't help at all.

EDIT ==============

I also forgot to mention that when I created the base page classes, I had to add using System.Web.UI; to the tops of the files, but intellisense.

Also (and this is the big one) I created a new web site (as opposed to a web app), and all of the problems I described above disappeared. Why does it make a difference?
Posted
Updated 10-Apr-11 1:20am
v2

Hi John,
For a web application there is no predefined folder to keep the codes. Either you can directly add the classes, that is not the good way. So you can add a new folder (any name). As you are added the App_Code folder, the classes inside may have the namespace like Your application name.your folder name . So you have to access the classes like App_code.your class name. Else remove the folder name from the namespace, you can access the classes directly.

Hope this helps.
 
Share this answer
 
Comments
#realJSOP 10-Apr-11 8:03am    
Yeah, I tried all that stuff before posting. No joy. See my edit to the original question.
Espen Harlinn 10-Apr-11 12:43pm    
It should - my 5 :)
0) When I create a class, the App_Code folder isn't automagically created for me.
When you add just a class to the root for the first time, it should ask you to place it in App_Code folder. If it does not exists, it creates one. In case this has not happened with you then, try creating the folder manually and place the class file there. (Once you create the folder, it's color would automatically change to some other color then a general folder color.)

1) I've written a BasePage class that inherits from System.Web.UI.Page. When I type that out, intellisense doesn't change the color of Page like I'm used to (but it's not underlinedeither to indicate an error).

2) When I try to use the BasePage class elsewhere in the site, it says it can't find it when I try to view a page in the browser.
Looks like it did not configure correctly. It should change color and give access. Try with BasePage in App_Code if not done till now. I really doubt it should be because of WebApp & Website difference.

If after trying with App_Code folder, you are still facing the issue, do share across your observations, I would like to repeat & replicate it on my system.
 
Share this answer
 
Comments
#realJSOP 10-Apr-11 7:12am    
0) Create the f9older manually - that's what I did. When I added the classes to that folder, I did remove the folder name from the namespace declaration, but that didn't help either.

2) Seems like *what* didn't configured correctly? I know the app sees the folder because I put a static class in there that I can call. It's just that it doesn't see the base pages.
Espen Harlinn 10-Apr-11 12:57pm    
Good effort, 5ed!
Hi John - did you remember to update your web.config?
XML
<compilation debug="false">
    <codeSubDirectories>
        <add directoryName="VBCode" />
        <add directoryName="CSCode" />
    </codeSubDirectories>
</compilation>


Look here for more info[^]

It's just a thought :-D

Graciously, yours truly,
Espen Harlinn
 
Share this answer
 
Comments
Albin Abel 11-Apr-11 4:42am    
Good point. My 5
Espen Harlinn 11-Apr-11 15:18pm    
Thanks Albin!
Hi John,

This what I did. I created a foder named Pages in the web application. Inside the Pages folder I added a Partial Class.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
namespace WebApp2.Pages
{
    public partial class BasePage:Page
    {
    }
}

WebApp2 is the application name.

Then at the Page markup I use it as follows

XML
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
      CodeFile="~/Pages/BasePage.cs" CodeFileBaseClass="WebApp2.Pages.BasePage" Inherits="WebApp2.Pages.BasePage"  %>


In an another test, I inherit this basePage class in the code behind like this.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApp2.Pages;
namespace WebApp2
{
    public partial class _Default : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("Hello");
        }
    }
}



In the markup

XML
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
      CodeFile="~/Default.aspx.cs"  Inherits="WebApp2._Default"  %>


However intellisense doesn't works, but it has no error and works fine. Is this example not work at your side?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900