change custom contol image based on user data in control des

Posted by Community Admin on 03-Aug-2018 23:44

change custom contol image based on user data in control designer

All Replies

Posted by Community Admin on 03-Jan-2011 00:00

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 ?

Posted by Community Admin on 04-Jan-2011 00:00

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

Posted by Community Admin on 04-Jan-2011 00:00

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.

Posted by Community Admin on 04-Jan-2011 00:00

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

This thread is closed