开发者

.Net 3.5 NameSpace Problem?

开发者 https://www.devze.com 2023-02-08 03:23 出处:网络
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

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" In开发者_运维技巧herits="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.

0

精彩评论

暂无评论...
验证码 换一张
取 消