开发者

Problems in the global namespace when I try to use my custom server control (in the App_Code directory)

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.


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


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜