2009-04-20 58 views
0

我試圖在以前的網站中開始使用DynamicData功能。基本上我跟着this tutorial。當我接觸到創建字段模板的部分時,我決定可以創建一個內置動態數據內容的新站點,然後將文件夾複製過來。如何從其他網站複製DynamicData模板?

不幸的是,當我這樣做,並嘗試編譯時,我收到DynamicData目錄中的每個.ascx文件的錯誤「無法加載類型...」。我將「新」項目命名爲與現有站點相同,以使命名空間相同......但我想不出還有什麼可能會丟失。

除了在解決方案資源管理器中顯示* .ascx.Designer.cs文件之外,一切都看起來不錯。我嘗試刪除一個,然後將該文件複製回目錄中,但它不起作用。我假設我需要做一些特殊的事情,以便Visual Studio正確處理它們並可以編譯?

這裏是.aspx文件之一:

<%@ Control Language="C#" CodeBehind="FilterUserControl.ascx.cs" Inherits="EService.FilterUserControl" %> 

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" 
    EnableViewState="true" ontextchanged="new"> 
    <asp:ListItem Text="All" Value="" /> 
</asp:DropDownList> 

這裏是匹配的cs文件:

using System; 
using System.Data; 
using System.Configuration; 
using System.Collections; 
using System.Collections.Specialized; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Xml.Linq; 
using System.Web.DynamicData; 

namespace EService 
{ 
    public partial class FilterUserControl : System.Web.DynamicData.FilterUserControlBase 
    { 
     public event EventHandler SelectedIndexChanged 
     { 
      add 
      { 
       DropDownList1.SelectedIndexChanged += value; 
      } 
      remove 
      { 
       DropDownList1.SelectedIndexChanged -= value; 
      } 
     } 

     public override string SelectedValue 
     { 
      get 
      { 
       return DropDownList1.SelectedValue; 
      } 
     } 

     protected void Page_Init(object sender, EventArgs e) 
     { 
      if (!Page.IsPostBack) 
      { 
       PopulateListControl(DropDownList1); 

       // Set the initial value if there is one 
       if (!String.IsNullOrEmpty(InitialValue)) 
        DropDownList1.SelectedValue = InitialValue; 
      } 
     } 
    } 
} 

這裏是.ascx.designer.cs文件:

//------------------------------------------------------------------------------ 
// <auto-generated> 
//  This code was generated by a tool. 
//  Runtime Version:2.0.50727.1433 
// 
//  Changes to this file may cause incorrect behavior and will be lost if 
//  the code is regenerated. 
// </auto-generated> 
//------------------------------------------------------------------------------ 

namespace EService 
{ 


    public partial class FilterUserControl 
    { 

     protected System.Web.UI.WebControls.DropDownList DropDownList1; 
    } 
} 

編輯:如果我在網站中創建文件,然後從我創建它的臨時網站複製內容似乎編譯就好。真的不知道這裏的問題是什麼......我嘗試手動修改文件來匹配複製的結果,除非我真的在網站上創建它們,否則它們將無法工作。這只是奇怪的...

回答

0

該問題是由於臨時網站使用CodeBehind屬性而不是CodeFile屬性創建了<%@ Control>定義。出於某種原因,在頁面的實際網站的CodeFile公佈時,將只編譯...