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:
- In the context menu of the project, click Add » New Item...
- In the left pane, select Visual C# Items » Web.
- Click JScript File and in the Name input field, enter DatePickerField.js
- Open the newly created file.
- Create the namespace for the client code.
- Define the client class.
- Define the prototype for the class.
- To get and set the field value, implement get_value and set_value client side methods.
- Register the client class and specify its base class.
- Save the file.
- 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.