Got an asp.net 3.5 app - compiles fine, but when browse to page I get the error below.
Searches for this all seem to indicate it is a namespace problem, but all of my pages seem to declare the proper namespace.
Any assistance appreciated!
Phil J.
Server Error in '/Internet/bm2/bm2' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: 'bm2.PolicyLookup' is not allowed here because it does not extend class 'System.Web.UI.Page'.
Source Error:
Line 1: <%# Page Language="vb" AutoEventWireup="false" CodeBehind="PolicyLookup.aspx.vb" Inherits="bm2.PolicyLookup" validateRequest="false" aspcompat="true"%>
Line 2:
Line 3:
Source File: /internet/bm2/bm2/policylookup.aspx Line: 1
=======
The System.Web.UI.Page is indeed inherited from in the code-behind:
Namespace bm2
Public Class PolicyLookup
Inherits System.Web.UI.Page
Protected WithEvents lblResponse As Label
Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
Dim myModel As New bm2.Model
Dim postData
Public objMessage
If this is a namespace problem (very unlikely), you'll either need to add an #import statement to your page:
<%# Import namespace=”My.Namespace.Where.bm2.PolicyLookup.Exists” %>
or modify your #Page directive to include the fully-qualified class name
....inherits="My.Namespace.bm2.PolicyLookup"
Of course, this only works if bm2.PolicyLookup descends from System.Web.UI.Page.
The #Page attribute
inherits="bm2.PolicyLookup"
tells ASP.NET that the class bm2.PolicyLookup inherits from System.Web.UI.Page, and that it should be instantiated when processing the page to handle on_load(), render(), etc events. However, ASP.NET believes that your class bm2.PolicyLookup does not inherit from System.Web.UI.Page, thus the error.
In order for the webforms engine to be able to process your page, it has to descend from the existing Page class. That class provides all of the event handlers, rendering methods etc. that are required.
Also, a bit of unrelated advice: Visual Studio hides a lot of functionality when working with a VB.Net site. Consider moving to C#, and to a web application project instead of a website project.
I don't know if there is a PolicyLookup class in System.Web (I don't think there is), but I ran into a similar problem when I tried to name a page SiteMap.aspx, since there was a type named SiteMap (though it was in a different namespace, it still seemed to cause a problem). The fix was to either rename completely, or have the code behind class name be prefixed with an underscore (you may have to update the Page directive in your aspx to match the new type name.
Related
In the source code for a VB ASP.NET website that I'm trying to get compiling, I've got a couple of "The file 'bla.aspx.vb' does not exist" errors; there is a corresponding .aspx file, but it's missing its companion .aspx.vb code-behind file.
The error msg displays because of this in the .aspx file:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Bla.aspx.vb" Inherits="cms_ShowEscalatorRule" %>
To just get the project compiling (this is just for running the project locally, the code I change won't affect the production code), would it be preferable to:
0) Comment out that section entirely
1) Remove the "CodeFile="Bla.aspx.vb" portion
2) Add a code-behind file
If the last option is best, what needs to be in it for a minimal amount of code - just enough to prevent the "missing file" error?
It's rather macabre to me that there is no contextual menu item for .aspx files that allows a minimal corresponding .aspx.vb to be created.
You may have to have a file because the .aspx may have references (and you will have to recreate those in the code-behind) to items from the code-behind file.
The minimum that's needed is a class inheriting from Page:
public class Bla : System.Web.UI.Page
{
}
This - of course - is not mandatory - you may as well use the alternative approach and inline the code-behind in a server-side script block in the .aspx file. Former approach however is much neater.
G. Stoynev basically had what I needed, but since this is VB, I had to change it to:
Public Class Bla
Inherits System.Web.UI.Page
End Class
I have never used VB before, so I used this to make the translation.
Currently I'm utilizing a base page class for my website declared like so:
Public Class BasePage
Inherits System.Web.UI.Page
and subsequent pages inherit that using:
Partial Class Default
Inherits BasePage
I have a function in the base page class that I want to be able to use from the pages that inherit the class. The function I have is declared:
Public Function GetSiteVers(ByVal parType As String) As String
When I attempt to call from a page that is inheriting the class:
Me.GetSiteVers("Misc")
I get the error
"GetSiteVers is not a member of Default"
or just
GetSiteVers("Misc")
I get the error:
'GetSiteVers' is not declared. It may be inaccessible due to its protection level.
I've different declarations and Vis Studio's intellisense finds no errors and when I build the page locally I get no compiler errors. Anyone have any ideas or suggestions?
The steps taken to correct this were:
Delete existing Basepage class file from App_code (BasePage.vb)
Reload page that was throwing the error (resuting in an obvious error, but forcing a recompile of the web without the class (clears out cached temp files I assume)
Copied back over BasePage.vb to App_Code
Reloaded offending page and it loaded without error
I'm assuming that this is the fashion in which to clear out any cached/temp files being referred to in the web. Odd way of doing it, but when you don't have complete control of IIS I guess that's the path one has to take.
There is already a question in stackoverflow where there is an error for a web application the compiler cannot find the load type.
This is not like that at all. This is a Web Site and the problem is in the building of the code when it looks for namespaces and definitions that already exist in the code.
This compilation error points to the first line of .master file and refers to an "Inherits" assignment.
The code behind only shows a warning, not an error. Any suggestions?
Your master page declaration should look like (presuming all files on same level in directory):
<%# Master Language="C#" AutoEventWireup="true" CodeFile="Admin.master.cs"
Inherits="Applications" %>
Your code-behind declaration should look like this:
public partial class Site : System.Web.UI.Page
{
...
}
If you were using VS, then it should have done this automatically for you. Are you sure this is not a Web Application project template?
In any case, your page code-behind should be inheriting from the page type; in your case, you are inheriting from a user control (master page is a user control).
I am trying to pass a value between two pages. However on my target page, the value is not found.
My source page includes the following code.
Public ReadOnly Property SQLString() As String
Get
Return "SELECT * FROM City"
End Get
End Property
On my target aspx page I have included the following directive:
<%# PreviousPageType VirtualPath="~/tools/SearchResults.aspx"%>
In the target page code behind I have included the following in the page load:
Me.Master.Page.PreviousPage.SQLString
However, Visual studio complains that, SQLString is not a member of System.Web.Ui.page.
I must note I am useing master pages, and vaguely recall this causing an issue when accomplishing this in the past. Anyone have any ideas?
You need to cast the page to whatever type it actually is.
CType(Me.Master.Page.PreviousPage, ActualPageType).SqlString
In the code behind of your source page you will have a class declaration like the following:
Public Class ActualPageType
Inherits Page
This is driving me absolutely nuts.
I created a new WAP project in VS 2008. Copied over the files in my Web Site Project. Added any required references. Tried to convert the Web Project to a Web Application using the "Convert to web application".
None of my user controls are able to see methods in their code behind. They don't even see them so I get errors everywhere saying it doesn't know what this or that method is.
Example:
<%=CreateMenu(xxx.WebMenuType.Occasion, "menuShopOccasion", "Occasion") %>;
That is in my Header.ascx
And so it errors out because it has no clue what CreateMenu is!
In my Header.ascx.cs it's there and was being referenced with no problem in my old Web Site Project:
protected string CreateMenu(xxx.WebMenuType menuType, string menuID, string title)
{
...
}
It's probably a namespace problem. Make sure that the Inherits attribute in your <%# Page ... %> declaration refers to the correct path to the code behind file, including the namespace. The designer file must also be in the same namespace as the code behind.
I am not entirely sure this is your problem but....
you may be missing the .designer.cs files. For your example above there would also be a Header.ascx.designer.cs which contains a partial class (Header) which has all the declarations of the controls in the Header.ascx file?