Data-Binding Expression Syntax in Composite Control
Having Trouble Understanding How Composite Controls Work
My process usually consists of creating a UserControl and then adding properties to the CodeFile and then calling DataBind() method on the UserControl.
public
class
someusercontrol : UserControl
public
String FirstName
get
;
set
;
someusercontrol ()
FirstName =
"Default FirstName"
;
protected
void
Page_Load(Object sender, Event Args e)
DataBind();
<%@ Page ...>
Hi my name
is
<%# FirstName %>
Hello jwize,
You can make a reference to the controls from your template using the container
sample
protected virtual TextBox TextBox
get
return this.Container.GetControl<TextBox>("TextBox1", true);
The you can bind these controls inside InitializeControls or CreateChildControls.
Best wishes,
Ivan Dimitrov
the Telerik team
I have no problem referencing controls in the view template.
I already understand the code you gave me and how it works.
How would take care of this scenario using html and tokens as I described in my question?
<%@ Control Language="C#" %>
<
style
type
=
"text/css"
>
.gallery-item
text-align: center;
width: <%# ThumbWidth %>px;
.gallery-image
width: <%# ThumbWidth %>px;
padding: <%# PaddingTop %>px <%# PaddingRight %>px <%# %>px <%# PaddingLeft %>px;
</
style
>
<
div
class
=
"gallery-item"
>
<
a
href='<%# Thumbnail %>' title='<%# Description %>' rel="lightbox">
<
img
class
=
"gallery-image"
src='<%# Image %>' />
</
a
>
<
p
><%# Description %></
p
>
</
div
>
Hello jwize,
There is a widget templates editor that will allow your users to make changes.
This is how you can store a template using the ControlPresentation persistent object.
var manager = PageManager.GetManager();
var template = manager.CreatePresentationItem<ControlPresentation>(id);
template.DataType = Presentation.AspNetTemplate;
template.Name = name;
template.ControlType = controlType;
////If the template is embedded you can use those properties::
template.EmbeddedTemplateName = embeddedResourcePath;
template.ResourceAssemblyName =
"Telerik.Sitefinity.Resources.Reference, Telerik.Sitefinity.Resources"
;
template.IsDifferentFromEmbedded =
false
;
//Else just set the Data Property to the markup
template.Data = markup;
template.IsDifferentFromEmbedded =
true
;
manager.SaveChanges();
var pageManager = PageManager.GetManager();
var layoutTemplates = pageManager.GetPresentationItems<ControlPresentation>()
.Where(tmpl => tmpl.DataType == Presentation.AspNetTemplate);
int
? totalCount = 0;
var filterExpression = String.Format(@
"ControlType == "
"0"
""
,
this
.DesignedDetailViewType);
layoutTemplates = DataProviderBase.SetExpressions(layoutTemplates, filterExpression, String.Empty, 0, 0,
ref
totalCount);
//This function will open the a template editor dialog in edit mode or create mode depending on the 'viewMode' value.
// the appropriate values can be found in the server side constants:
//ControlTemplatesDefinitions.BacknedEditDetailsViewName
//ControlTemplatesDefinitions.BacknedInsertDetailsViewName
_openTemplateDialog:
function
(string viewMode)
//The RadWindow component that will open the widget template editor.
if
(
this
._widgetEditorDialog)
//The resolved ~/Sitefinity/Dialog/ControlTemplateEditor
var
dialogUrl =
new
Sys.Uri(
this
._resolvedTemplateEditorDialogUrl);
dialogUrl.get_query().ViewName = viewMode;
this
._widgetEditorDialog.set_navigateUrl(dialogUrl.toString());
dialogBase.get_radWindow().maximize();
this
._widgetEditorDialog.show();
this
._widgetEditorDialog.maximize();
$(
"body"
).removeClass(
"sfSelectorDialog"
);
,
_onWidgetEditorShown:
function
(sender, args)
var
frameHandle = sender.get_contentFrame().contentWindow;
if
(frameHandle)
if
(frameHandle.createDialog)
var
params =
//The id of the template that you wish to edit or Guid.Empty
TemplateId:
this
._selectedTemplateId,
//The type of the control to which the template was registered.
ControlType:
this
._controlType
;
frameHandle.createDialog(
null
,
null
,
null
, dialogBase, params,
null
);
,