RadControls for ASP.NET AJAX

RadControls for ASP.NET AJAX .

This tutorial assumes that you have a Visual Studio solution with a DNN website. RadScheduler is used as an example, but similar approach can be applied to other Telerik controls for ASP.NET AJAX.

Follow the listed steps to create a DNN Module that utilizes RadScheduler.

1. Right-click the ‘DesktopModules’ folder and select New Folder. Name the new folder ‘RadScheduler’.

new folder

2. Right-click the new folder and select ‘Add New Item’. Select the Web User Control template and rename it to RadScheduler.ascx. Select the language of your preference.

creating scheduler web user control

3. Open the newly created User Control and go to Design Mode. Drag a RadScheduler instance from the Toolbox in the User Control content.

drag RadScheduler from toolbox

4. Go to Source Mode and add the following properties to RadScheduler:

CopyXML
<telerik:RadScheduler DataKeyField="ID" DataSubjectField="Subject" DataStartField="Start"
    DataEndField="End" ID="RadScheduler1" runat="server"></telerik:RadScheduler>

You can also set these properties through the property grid in Design Mode.

5. The next step is to turn the newly created User Control into a DNN Module. To do this, open the CodeBehind file of the User Control (RadScheduler.ascx.cs or RadScheduler.ascx.vb) and make RadScheduler inherit from DotNetNuke.Entities.Modules.PortalModuleBase.

6. To add the Module to a DNN page, you should register it first. Log in as the Host account and go to the Host > Module Definitions page. Select Create ModuleDefinition either from the Action menu or through the link near the bottom.

module definitions

7. Type ‘RadScheduler’ in the Module Name, Folder Name and Friendly Name textboxes on the Create Module Definition page. Click the ‘Create’ button to continue.

8. On the next page, type ‘RadScheduler’ in the New Definition textbox and click the Add Definition button next to it. Click the Add Control button that appears.

9. On the Edit Module Control page click the Source dropdown and select the RadScheduler.ascx created earlier. Fill ‘RadScheduler’ in the Title textbox. Click the Update button to finish.

Tip

Optional: You can click the Supports Partial Rendering? checkbox if you want the module to be updated through AJAX.

edit module control

10. The RadScheduler Module should now be available in the Module dropdown when editing a page. You can go to a page of your choice and add the module to make sure everything works properly. Note that the Module is not yet fully functional and any appointments that you add won’t be saved.

RadScheduler in content pane

11. To save the appointments, we first need to create an Appointments table in the DNN Database. To do this, go to the Host > SQL page of your DNN website. Paste the following script in the textbox, check the Run as Script checkbox and click Execute:

CopyXML
CREATE TABLE [{objectQualifier}Appointments]   
(   
  [ID]                    INT IDENTITY(1,1)   NOT NULL,
  [ModuleId]              INT                 NOT NULL,   
  [Subject]               nvarchar(255)       NOT NULL,   
  [Start]                 datetime            NOT NULL,   
  [End]                   datetime            NOT NULL,   
  [RecurrenceRule]        nvarchar(1024)      NULL,   
  [RecurrenceParentID]    INT                 NULL,   

  CONSTRAINT [PK_Appointments] PRIMARY KEY CLUSTERED    
      ([ID]),   

  CONSTRAINT [FK_Appointments_ParentAppointments] FOREIGN KEY   
      ([RecurrenceParentID])   
  REFERENCES   
      [{objectQualifier}Appointments] ([ID])   
)

12. Go back to Visual Studio and open the RadScheduler.ascx in Design Mode. Drag a SqlDataSource control from the toolbox. Right-click the new SqlDataSource control and select Configure Data Source (the option is also accessible from the Smart Tag of the control).

SqlDataSource

Configure Data Source

13. From the connection dropdown select SiteSqlServer. This is the connection string that the DNN Installation is using. Click Next.

choose data connection

14. On the next screen, select the Appointments table we created earlier. In a default DNN installation it will be called ‘dnn_Appointments’, but the prefix may differ in your case. Check the asterisk (*) checkbox.

configure the select statement

15. Click the Advanced… button and check the first checkbox labeled Generate INSERT, UPDATE and DELETE statements. Click Ok.

generate Insert, Delete and Update statement

16. Click the WHERE… button. In the popup window, select ‘ModuleId’ in the Column dropdown, select ‘=’ in the Operator dropdown and select ‘None’ in the Source dropdown. Click Add and then click Ok.

add where clause

17. Click Next and then click Finish on the next screen to complete the DataSource configuration.

test query

18. While still in Design Mode, right-click RadScheduler and select Choose Data Source. Configure the dropdowns as shown on the screenshot. Click Ok.

set RadScheduler datafield properties

19. Go to Source mode and modify the DeleteCommand property of the SqlDataSource to look like thisDeleteCommand="DELETE FROM [dnn_Appointments] WHERE ([ID] = @ID AND [ModuleId] = @ModuleId)"

Also edit the DeleteParameters to look like this:

CopyXML
<DeleteParameters>
    <asp:Parameter Name="ID" Type="Int32" />
    <asp:Parameter Name="ModuleId" Type="Int32" />
</DeleteParameters>

20. Go back to Design mode, right-click the SqlDataSource control and select Properties. Click the Events button then double-click the Selecting event to generate an event handler. Repeat this for the Insert, Updating and Deleting events.

SqlDataSource events

21. In the CodeBehind file (RadScheduler.ascx.cs or RadScheduler.ascx.vb) insert the following code in each Event Handler:

The CodeBehind file should now look like this:

22. Save the files and reload the test page with the RadScheduler Module. Everything should be working fine now.