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

Forums / Developing with Sitefinity / Custom field Client Control JS file inclusion

Custom field Client Control JS file inclusion

2 posts, 1 answered
  1. Jeff
    Jeff avatar
    2 posts
    Registered:
    31 Oct 2013
    31 Oct 2013
    Link to this post
    I'm trying to develop a custom field using the steps outlined here: http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/controls/types-of-controls/field-controls/building-a-custom-field-control

    Unfortunately, I don't know how/where to include the client control js file, and it doesn't seem to say in the documentation. Can anyone explain how I might do this?
    I'm very new to Sitefinity dev (as in this is the first thing I've done) and web dev in general, so feel free to suggest things that "should be obvious"

    Question is also on StackOverflow
    Answered
  2. Jeff
    Jeff avatar
    2 posts
    Registered:
    31 Oct 2013
    01 Nov 2013 in reply to Jeff
    Link to this post
    Ok, got it.
    First you need to set the processing options for the js file to Embedded Resource
    Then add it to the AssemblyInfo.cs:
        [assembly: WebResource("namespace.filename.js", "text/javascript")]
    Then override the GetScriptReferences method in the class that inherits from FieldControl:
    public override IEnumerable<ScriptReference> GetScriptReferences()<br>{<br>    var baseReferences = new List<ScriptReference>(base.GetScriptReferences());<br>    var newRef = new ScriptReference(javascriptPath, this.GetType().Assembly.FullName);<br>    baseReferences.Add(newRef);<br>    return baseReferences;<br>}


2 posts, 1 answered