Browse and replace image implementation in custom control
Hi guys,
I'm new to sitefinity.
I have a custom user control that was already made and looks like this :
namespace
SitefinityWebApp.UserControls
//[ControlDesigner(typeof(SitefinityWebApp.Class.UserControlDesigner))]
public
partial
class
ImageComponent : System.Web.UI.UserControl
private
string
m_ImageUrl =
string
.Empty;
public
string
ImageUrl
get
return
m_ImageUrl;
set
m_ImageUrl = value;
protected
void
Page_Load(
object
sender, EventArgs e)
<%@ Control Language=
"C#"
AutoEventWireup=
"true"
CodeBehind=
"ImageComponent.ascx.cs"
Inherits=
"SitefinityWebApp.UserControls.ImageComponent"
%>
<%
if
(ImageUrl!=
string
.Empty) %>
<img src=
"<%=ImageUrl %>"
alt=
""
/>
<% %>
Hello Alex,
You have to implement a custom control designer that wraps MediaContentSelectorView .
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Modules.Libraries.Web.UI.Designers" TagPrefix="sf" %>
<
sf:MediaContentSelectorView
id
=
"selectorView"
runat
=
"server"
ContentType
=
"Telerik.Sitefinity.Libraries.Model.Image"
ParentType
=
"Telerik.Sitefinity.Libraries.Model.Album"
LibraryBinderServiceUrl
=
"~/Sitefinity/Services/Content/AlbumService.svc/"
MediaContentBinderServiceUrl
=
"~/Sitefinity/Services/Content/ImageService.svc/"
MediaContentItemsListDescriptionTemplate
=
"Telerik.Sitefinity.Resources.Templates.Designers.Libraries.Images.ImageItemDescriptionTemplate.htm"
DisplayResizingOptionsControl
=
"false"
ShowOpenOriginalSizeCheckBox
=
"false"
>
</
sf:MediaContentSelectorView
>
Hi Ivan,
Thanks for your solution.
However I haven't been able to test it yet. I forgot to mention one aspect. I need to do the changing of the image url property from inside the edit of the user control.
I managed to implement a custom control designer using both your link and took the files from here. The problem I get now is that when I place the first line
[ControlDesigner(typeof(SitefinityWebApp.UserControls.UserControlDesigner))]
public partial class ImageComponent : System.Web.UI.UserControl
private string m_ImageUrl = string.Empty;
[WebEditor("Telerik.Libraries.WebControls.ImageSelector, Telerik.Libraries")]
public string ImageUrl
get return m_ImageUrl;
set m_ImageUrl = value;
protected void Page_Load(object sender, EventArgs e)
Hello Alex,
There is something wrong with the UserControlDesigner
or you have not set the client component for it.
All the best,
Ivan Dimitrov
the Telerik team
Hi Ivan,
How do I set the client component?
Thanks,
Alex
Hello Alex,
This is documented in the tutorial that I sent you - Writing the JavaScript for the dialog
Greetings,
Ivan Dimitrov
the Telerik team
Hi Ivan,
Thanks for the reminder. I have set the client component like in the example, added something simple.
The problem however is the same , I realized it was from a js error which I couldn't see before because I was using chrome and didn't have debugger enabled.
In IE with JS debugger enabled the application breaks at this line from the js :
SitefinityWebApp.UserControls.registerClass('SitefinityWebApp.UserControls.UserControlDesigner', Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesignerBase);
Type.registerNamespace(
"SitefinityWebApp.UserControls"
);
SitefinityWebApp.UserControls.UserControlDesigner =
function
(element)
SitefinityWebApp.UserControls.UserControlDesigner.initializeBase(
this
, [element]);
SitefinityWebApp.UserControls.UserControlDesigner.prototype =
initialize:
function
()
SitefinityWebApp.UserControls.UserControlDesigner.callBaseMethod(
this
,
'initialize'
);
,
dispose:
function
()
SitefinityWebApp.UserControls.UserControlDesigner.callBaseMethod(
this
,
'dispose'
);
,
refreshUI:
function
()
,
applyChanges:
function
()
SitefinityWebApp.UserControls.registerClass(
'SitefinityWebApp.UserControls.UserControlDesigner'
, Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesignerBase);
if
(
typeof
(Sys) !==
'undefined'
) Sys.Application.notifyScriptLoaded();
Hi Alex,
I think that there is conflict in the way that you are registering the client side component. Pleas make sure that you use proper typename and base class. You can take a look at Type.registerClass Method
All the best,
Ivan Dimitrov
the Telerik team