2

Traditionally I use the regular asp.net website (created using the File > New Website). Recently, I opted to work off of a full fledged project (created using File > New Project > ASP.net Web Application).

I've been using the same custom controls for years without incident. I simply create the new website, place my CustomControls.cs file in the App_Code directory, add one line to the web.config file and I can use all of my custom server controls. When I try that with my web project I get the following error

Error 225 The type or namespace name 'DTF' could not be found in the global namespace (are you missing an assembly reference?) D:[Project Location On Drive]\AgIn02.aspx.designer.cs

My custom control file looks like this

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace DTF.Web.UI
{

    public class IntOnlyBox : TextBox
    {
        private RequiredFieldValidator rfv;
        private ValidatorCalloutExtender vce;
        private AjaxControlToolkit.FilteredTextBoxExtender ftb;
        private string strInvalidMessage = "";
        private string strValidationGroup = "";

        public string ValidationGroup
        {
            get
            {
                return strValidationGroup;
            }
            set
            {
                strValidationGroup = value;
            }
        }


        public string InvalidMessage
        {
            get
            {
                return strInvalidMessage;
            }
            set
            {
                strInvalidMessage = value;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            rfv = new RequiredFieldValidator();
            rfv.ControlToValidate = this.ID;
            rfv.ErrorMessage = "<span style=\"color:black\"><b>Required Field Missing</b><br />" + this.InvalidMessage + "</span>";
            //rfv.ErrorMessage = this.InvalidMessage;
            rfv.ID = "rfv" + this.ID;
            rfv.Display = ValidatorDisplay.None;
            rfv.SetFocusOnError = true;
            rfv.EnableClientScript = true;
            rfv.ValidationGroup = this.ValidationGroup;

            vce = new AjaxControlToolkit.ValidatorCalloutExtender();
            vce.ID = "vce" + this.ID;
            vce.TargetControlID = "rfv" + this.ID;
            vce.Width = 300;

            ftb = new FilteredTextBoxExtender();
            ftb.ID = "ftb" + this.ID;
            ftb.TargetControlID = this.ID;
            ftb.FilterType = FilterTypes.Numbers;

            Controls.Add(rfv);
            Controls.Add(vce);
            Controls.Add(ftb);
        }

        protected override void Render(HtmlTextWriter w)
        {
            //w.Write(this.InvalidMessage);
            base.Render(w);
            rfv.RenderControl(w);
            vce.RenderControl(w);
            ftb.RenderControl(w);
        }
    }

}

my web.config entry looks like this (in the pages/controls area)

<add tagPrefix="DTF" namespace="DTF.Web.UI" />

I've tried everything I can think of to get this to work and compile. The intellisense for the custom server controls works fine, it simply won't compile.

I also get the error "The base class includes the field 'blanro', but its type (DTF.DateBoxFull) is not compatible with the type of control (DTF.DateBoxFull)."

Any idea how to fix this, and why it would work in the regular asp.net website but not in a web project?

Thanks Everyone.

Steve French
  • 961
  • 3
  • 13
  • 38

4 Answers4

1

Compile your custom classes to a .dll and add a reference to your project.

Gthompson83
  • 1,099
  • 1
  • 8
  • 18
  • I'm trying to avoid doing that so I can make easy spot changes. – Steve French Nov 04 '10 at 19:12
  • I'd say that this is your best option. As for your "Spot Changes" it doesn't take much to add a Post-Build Bat file in order to do an XCopy to the web project bin directories. The only thing that you will run into is if your "Spot Changes" are to change per solution, which isn't a great coding practice – cory-fowler Nov 06 '10 at 19:01
0

Well, to answer it simply WAP and Web Site have a different way of compiling the applications and hence you may be seeing this behavior.

Rahul Soni
  • 4,941
  • 3
  • 35
  • 58
  • I do realize that, my problem is how to get the WAP to compile. Any thoughts on that? – Steve French Nov 01 '10 at 17:27
  • Afaik, it won't. You will need to write the custom controls and compile them. Then you would need to incorporate them in your project as you would for any other control. App_code is better in an Asp.net web site, since it doesn't require all of that. You may recall that wap is Vs2003 way of creating project, App-code is vs2005 and beyond. – Rahul Soni Nov 02 '10 at 01:49
  • Alas, it does seem to be that way, it is an interesting omission on Microsoft's part. All I was trying to do was get the one-click publishing to work on this particular project, but it seems not to be that way. – Steve French Nov 02 '10 at 15:12
0

When using a WAP, it's best not to put your custom control in App_Code. Instead, simply put that code somewhere else in your project, and you should be able to use the control from your pages without problems.

David Ebbo
  • 42,443
  • 8
  • 103
  • 117
0

The App_Code directory in a WebApplication project has no effect. All code files, regardless of the directory in which it resides, are compiled into a single assembly, and that assembly is placed in the bin directory.

Just move all your files out of App_Code and then delete App_Code.

Max Toro
  • 28,282
  • 11
  • 76
  • 114