ImageUrl in user control mode

I created my own control with the ImageURL property. During development, when I enter an image in ImageUrl, I get the following error message

Error creating control - AmazeDropDownList1 '~ / Image / help.png' cannot be set in the ImageUrl property.

<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)]
    [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 inherit a TextBox, below is my render method:

    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
        // Call the base class 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 help in fixing the error message.

+3
source share
1 answer

I wonder if Visual Studios uses an incorrectly cached version of your controls?

. .

( ), (.. <%@ Register...), .

, Web.config, :

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

Source: https://habr.com/ru/post/1748862/


All Articles