1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / change custom contol image based on user data in control designer

change custom contol image based on user data in control designer

4 posts, 1 answered
  1. Phil
    Phil avatar
    89 posts
    Registered:
    19 Oct 2010
    03 Jan 2011
    Link to this post

    I have made a custom control.  How do I change the image file in an edit-a-page, ascx file  based on user input supplied in the control designer, ascx file ?

     

    Currently, in the Page_Load of the edit-a-page class file I am doing the following, and it is working fine.

    imageCircles.ImageUrl = (labelThree.Trim().Length > 0) ?
    "http://localhost:56287/Sitefinity/LessonBuilder/Images/Venn3Sets.png" :
    "http://localhost:56287/Sitefinity/LessonBuilder/Images/Venn2Sets.png";

    I want to load the desired image as an Embedded Resource.  The image files in Visual Studio have their Build Action property set to Embedded Resource, and are included in the AssemblyInfo.cs file like this:

    [assembly: WebResource("lbWidgets.VennDiagram.Resources.Venn2Sets.png", "img/png")]
    [assembly: WebResource("lbWidgets.VennDiagram.Resources.Venn3Sets.png", "img/png")]

    How do I change the image file in an edit-a-page, ascx file  based on user input supplied in the control designer, ascx file ?

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Jan 2011
    Link to this post
    Hi Phil,

    When you click "Save" button of the ControlDesigner - the InitializeControls method of your control is called and there you can set the ImageUrl.

    1. You need to have a property in you custom control.

    2. This property should be set in the java script of the Control Designer you have - applyChanges function which forces the designer to apply the changes on UI to the cotnrol Data

    3. Set the ImageUrl to the value of your property from ( 1 )  inside InitializeControls of the control you have.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Phil
    Phil avatar
    89 posts
    Registered:
    19 Oct 2010
    04 Jan 2011
    Link to this post
    OK.  I am setting the ImageUrl in the InitializeControls method.

    What I need help with is this:  I want to load the desired image from the Embedded Resources.  

    Currently,  t
    he image files in Visual Studio 1.) have their Build Action property set to Embedded Resource, and  2.) are included in the AssemblyInfo.cs file (see below).    

    Also see below for how I am currently setting imageCircles.ImageUrl  - using an http uri.   This is all working.

    The NewsRotator sample uses images as Embedded Resources in the css files in that project, like this
    background-image:url(<% = WebResource("NewsRotator.Resources.Icons.PlayButton.gif") %>);
    but I cant find an example of accessing the images-as-embedded-resources from the class file.

    How can I set the ImageUrl with the desired image from the Embedded Resources?

    Thanks for your help.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Jan 2011
    Link to this post
    Hi Phil,

    You can use standard ASP.NET code

    string resourceUrl = this.Page.ClientScript.GetWebResourceUrl(typeof(Telerik.Sitefinity.Samples.SimpleViewCustom), "Telerik.Sitefinity.Samples.Resources.searchmapping.png");
     
    ImageControl.ImageUrl = resourceUrl;


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
4 posts, 1 answered