Date picker widget: Implement the features of the control

Implement the client component

You must store the client class in a javascript file in the project, where the view resides.

You must include the following methods:

  • initialize
    This method is called when an instance of the class is created.
  • dispose
    This method is called when the instance of the class is no longer used.

To create the file, perform the following:

  1. In the context menu of the project, click Add » New Item...
  2. In the left pane, select Visual C# Items » Web.
  3. Click JScript File and in the Name input field, enter DatePickerField.js
  4. Open the newly created file.
  5. Create the namespace for the client code.
  6. Define the client class.
  7. Define the prototype for the class.
  8. To get and set the field value, implement get_value and set_value client side methods.
  9. Register the client class and specify its base class.
  10. Save the file.
  11. In the Properties pane of the DatePickerField.js file, change the Build Action to Embedded Resource.

GITHUB EXAMPLE: For more information about the content of the file, see the DatePickerField.js file of the downloaded sample project.

To create the namespace for the client code you call the registerNamespace of the Type class.

NOTE: The same namespace must be used throughout the entire client code in this file.

You register the client class by calling the registerClass method.

Reference the client script

To reference the client script and specify a script descriptor for the view, you must override the following methods:

  • GetScriptDescriptors
    In this method, the script for the client component is referenced.
  • GetScriptReferences
    In this method you can define an instance of your client class and set the desired properties to it.

You override GetScriptDescriptors and GetScriptReferences methods in the DatePickerField.cs.

GITHUB EXAMPLE: For more information about the content of the file, see the DatePickerField.cs file of the downloaded sample project.

You must reference the client component from the view class. You do this in the override for the GetScriptReference method. In it you create a script reference for your client component. When creating the reference, you must specify the name of the embedded resource that contains the client component and the assembly it resides in. In the GetScriptDescriptors method you specify a script descriptor for the view.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?