Press "Enter" to skip to content

Custom Control vs JavaScript Injection


K2 Smartofrms is a rich and powerful designer of user interfaces, which can help you build forms for applications of various complexity. Even though K2 Designer contains a lot of out-of-the-box components, events, actions, themes, we do not fully control the Document Object Model (DOM).  that is produced by the K2 Smartforms engine. But what if we need something non-standard? What if we need to exceed the limits?

From my experience, I can state with confidence, that depending on the project more than 90% of all requirements for user interfaces can be satisfied with the out-of-the-box components. The rest is always extensions of the platform, using custom controls or injection of JavaScript into the forms. Below I will try to give a short overview of Custom Control vs JavaScript Injection in K2 Smartforms.

1. Custom Control Development

Developers may create Custom Controls, i.e. web UI components, to extend the functionality and look of standard set of controls provided with K2 smartforms. A developer usually decides in favor of Custom Controls, when the required functionality is really complex and not just a minor tweak. When developing custom controls, you should always bear in mind the following:


  • It is the only well-maintainable way of extending Smartforms with additional functions. K2 lists Custom Control development as one of the possible extensions of K2 Smartforms.
  • A Custom Control can implement the number of control properties, methods and events, that can be later used in K2 Designer for configuration.
  • It can incorporate and load into the Smartforms various JavaScript frameworks, which can be one or more js files. The Custom Control includes the JavaScript frameworks into its assembly as embedded resources and you can control, when to load them.
  • Complex controls can be developed with the help of custom control development.
  • K2 has  Product Documentation, which describes, how Custom Controls can be developed


  • It requires the knowledge of C#, JavaScript, css.
  • K2 Documentation describes only basic functionality. If you need some advanced features, you might not find the required information.
  • Development may take a lot of time.
  • You cannot add Custom Controls to K2 Cloud.

2. JavaScript injection

JavaScript Injection is a process by which we can insert and use our own JavaScript code in a page. Here I mean a reasonable amount of JavaScript (1 or more lines of code), needed for a certain functionality. And by injection I also mean adding the JavaScript via K2 Designer and not via address bar OR by finding XSS vulnerability in a website. You can get more practical information in my next post on How to add JavaScript on Smartforms.


  • Quick implementation of a feature in comparison to a custom control.
  • JavaScript, included into the Form and/or View, is automatically included into the K2 Package, while the Custom Control needs to be deployed to all the environments beforehand.
  • It requires knowledge only JavaScript and maybe the Smartforms DOM, depending on the functionality needed.
  • It can be used in K2 Cloud and, probably, it is currently the only way to extend the Cloud platform.


  • It is not maintainable, unless all application developers/administrators know, that certain functionality uses JavaScript Injection onto Smartforms. Debugging can be really difficult, when the JavaScript is hidden in a form expression or hidden Data Label.
  • A couple of lines of JavaScript on the form cannot be used to implement complex elements. Depending on the complexity, it might be not possible to use JavaScript Injection.
  • Due to a Cannot be easily bound to Smartforms events and actions.

Summing it all up, each of the approaches (Custom Control vs JavaScript Injection) should be used with common sense care and always consider the requirements. For example, it might not be a good idea to create a custom control for some basic functionality, like Placing a View above the tabs.  And at the same time, JavaScript Injection will simply be not enough, if you need a custom Charting control.

Leave a Reply

Your email address will not be published. Required fields are marked *

one × 3 =