2012-10-09 25 views
1

我有一個可以與CodeFile正常工作的asp項目,但是當我將其更改爲CodeBehind時,vb函數無法在aspx文件中識別,並給出「Name ...未在aspx文件中聲明「錯誤。CodeFile好了,CodeBehind給出了「未聲明」的錯誤

爲了使用CodeBehind,除了在頂行中將codefile更改爲codebehind之外,還有其他一些應該完成的內容嗎?

以下代碼在aspx文件中獲取錯誤「名稱」連接未被聲明「。

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="browse.aspx.vb" Inherits="_browse" %> <!DOCTYPE html 
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html> 
<head runat="server"> <title>Test</title> </head> 
<body> 
<form id="form1" runat="server"> 
<div> 
<% 
    Dim s As String = connex() 
    Response.Write(s) 
%> 
</div> 
</form> 
</body> 
</html> 

==================

Imports System 
Imports System.Web 

Partial Public Class _browse 
Inherits System.Web.UI.Page 

Function connex() As String 
    Return "OK" 
End Function 

End Class 
+1

我相信當你的應用程序有一個根名稱空間,你可以在項目屬性中找到'inherits =「MyNameSpace._browse」'是必需的。我相信根名稱空間默認爲您的應用程序的原始名稱。如果沒有根名稱空間,'Inherits =「_ browse」'可能會起作用。在使用DNN時,我刪除了根名稱空間,但是我將其留在所有其他項目中。 –

回答

1

檢查

Inherits="_browse" 

確保包括正確的命名空間。

Inherits="MyNameSpace._browse" 
+0

謝謝!這就是它。我必須刪除代碼文件的名稱空間,並將其添加到代碼隱藏文件中。 – xpda

相關問題