views:

217

answers:

2

I'm attempting to start using DynamicData functionality in a previously existing website. Basically I'm following this tutorial. When I got to the part about creating the Field Templates I decided I could probably create a new site with the Dynamic Data stuff built in, and then just copy the folder over.

Unfortunately when I do that and try to compile I get the error "Could not load type..." for just about every .ascx file in the DynamicData directory. I named the "new" project the same as the pre-existing site so that the namespace would be the same... but I can't think of what else I could be missing.

Everything looks ok, except that the *.ascx.Designer.cs files are showing inside the Solution Explorer. I tried deleting one and then copying that file back into just the directory but it didn't work. I'm assuming I need to do something special with those so that Visual studio handles them properly and can compile?

Here is one of the .aspx files:

<%@ 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>

Here is the matching .cs file:

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;
            }
        }
    }
}

And here is the .ascx.designer.cs file:

//------------------------------------------------------------------------------
// <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;
    }
}

EDIT: If I create the file in the website, then copy the contents from the temporary site I created it seems to compile just fine. Really have no idea what the issue is here... I tried manually modifying files to match the results of copying and they still wouldn't work unless I actually created them in the site. It's just bizarre...

A: 

The problem was due to the temporary site creating the <%@ Control > definitions with the CodeBehind property instead of the CodeFile property. For some reason pages in the actual website will only compile when CodeFile is declared...

Telos
A: 

DD will work with Either Website or Web Application. however when copying in from an other project the types need to be the same otherwise it's lot of editing to convert swee my article here Getting Dynamic Data Futures filters working in a File Based Website.

Wizzard