change custom contol image based on user data in control designer
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 ?
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
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, the 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") %>);
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;