开发者

ImageUrl on Custom Control Design Time

I have build a Custom Control with an ImageURL property. At design time when I enter an image in the ImageUrl I get the following error message

Error Creating Control - AmazeDropDownList1'~/Image/help.png' could not be set on property 'ImageUrl'.

<myCompany:MyCompanyDropDownList ID="AmazeDropDownList1" runat="server" ImageUrl="~/Image/help.png">
</myCompany:MyCompanyDropDownList> 

The code for my control is shown below:

    [DefaultValue("")]
    [Editor("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
    [Description("Image_ImageUrl")]
    [Bindable(true)]
  开发者_StackOverflow  [Category("Appearance")]
    [UrlProperty]
    public virtual string ImageUrl
    {
        get
        {
            string str = (string)this.ViewState["ImageUrl"];
            if (str != null)
            {
                return str;
            }
            return string.Empty;
        }
        set
        {
            this.ViewState["ImageUrl"] = value;
        }
    }

I am inheriting from TextBox, below is my render method:

    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
        // Call the base class's Render method.
        base.Render(writer);

        if (!string.IsNullOrEmpty(this.ImageUrl))
        {
            // Create and render a new Image Web control.
            System.Web.UI.WebControls.Image image = new System.Web.UI.WebControls.Image();
            image.ID = "Image1";
            image.ImageUrl = ImageUrl;
            image.AlternateText = ImageAltText;
            image.RenderControl(writer);
        }
    }

I would really appreciate any help in fixing the error message.


I wonder if Visual Studios is using an incorrectly cached version of your control?

You can try and clear the cache yourself. Instructions here.

Or, you could try removing the control from the toolbox (if it's there), removing all the control references from the page (i.e. the <%@ Register... tags), rebuilding all, and then re-adding the control.

Final guess, reference the control within the Web.config instead of on the page:

<system.web>
 <controls>
  <add tagPrefix="my" namespace="myCompany.Controls" 
            assembly="myCompany.Controls"/>
 </controls>
</system.web>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜