views:

25

answers:

1

I am beginning to wonder if this is even possible. It just seems so simple.

I have a published web project. I want to add some .ascx files (with .cs & designer.cs files) to that published web site. These are simple custom user controls that access methods already part of the original application.

Question? Is it possible to just drop these in the published web project without building the entire solution? If not why?

When I drop these files in and run my application I get the error: "Parse Error: Could not load type 'the name of my custom controls namespace'".

There is not a lot of code to show so this is all I have.

Default.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPages/TwoColumn.master" AutoEventWireup="true"
    Inherits="ApplicationName.Web.Default" CodeBehind="Default.aspx.cs" %>

<%@ Register TagPrefix="uc1" TagName="CustomControl" Src="~/Controls/Custom/CustomControl.ascx" %>
<asp:Content ID="content" contentplaceholder="cph" runat="Server">
<uc1:CustomControl ID="cc1" runat="server" CustomProperty="Hello World" />
</asp:Content>

CustomControl.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CustomControl.ascx.cs"
    Inherits="ApplicationName.Web.Controls.Custom.CustomControl" %>
<asp:PlaceHolder ID="ph1" runat="server></asp:PlaceHolder>

CustomControl.ascx.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ApplicationName.Web.Controls.Custom
{
public partial class CustomControl : System.Web.UI.UserControl
{
///My logic
}
}

Again it seems so easy. What am I missing? Or is this not possible? Thanks.

UPDATE: I figured this out. The above scenario is possible. The problem is not with the name-space as the error message suggests. Rather it is the code-behind declaration. Code-behind files for any type of file are compiled when the application is published. I am still confused as to why it appears to be editable when you browse through a web directory, I would think it would be stored in a .dll file or something. Maybe someone can shed some light on this.

Anyways, replacing code-behind with code-file rectifies the problem as code-files are not compiled and are therefore readable at application run-time.

Some links that were helpful can be found here and here.

A: 

It is possible but you still have to compile your user control and drop that dll into the proper bin directory for your app. That's usually the cause of the type loading error you described.

Ken
I guess I still don't get it. When I publish the application there are numerous ascx files that are not compiled and work ok. Why couldn't I add another one? It sounds like there is somewhere the application is making references to the existing ascx files when building. ??