當我只是將具有代碼隱藏功能的aspx頁面複製(無需部署)到網站時,當我嘗試使用該頁面時,出現分析器錯誤消息。解析器錯誤複製帶有代碼隱藏的單個aspx頁面
讓我們假設這只是爲了測試目的,我想在Visual Studio中開發一個單獨的頁面,然後將它複製(或FTP)到一個網站。
完整的錯誤信息是:
Parser Error Message: Could not load type 'SimpleSite.WebForm2'.
的WebForm2.aspx文件是:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="SimpleSite.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
</form>
</body>
的WebForm2.aspx.cs文件是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SimpleSite
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox2.Text = TextBox1.Text;
}
}
}
我不確定是否t他的命名空間是問題,它似乎是。我用Expression Web創建了一個代碼隱藏的ASP.Net文件,我只能使用FTP ,但沒有名稱空間(是的,我知道它在全局名稱空間中)。
如果我想使用代碼隱藏功能製作一個或兩個aspx文件,僅用於教育目的而不需要部署就可以進行復制,我可以使用Visual Studio Web Project或Web Site來維護該頁面,使其仍然有效作爲Visual Studio Web Project或Web Site中的頁面?
您需要將其作爲網站,而不是Web應用程序項目。你需要複製它的任何依賴關係。 – mason
這是因爲Web站點是與Web應用程序項目不同而編譯的。 – niksofteng
@mason,你知道**它會作爲一個網站或你猜測嗎?無論我使用Web項目還是Web站點來創建代碼,代碼都是相同的,但如果我錯過了某些內容,請解釋其中的差異。當我使用網站時,我得到了相同的結果。另外,我提供了所有的代碼。錯誤信息的哪一部分表示缺少某些內容? – user34660