Jobs module: Create the frontend view
To create the job application upload form, perform the following:
Create the markup
- In Visual Studio, in your project, open the context menu of the Views folder and click Add » New Item...
NOTE: Visual Studio does not provide a dialog option to directly create a user widget. You must create a file of another type and change its extension.
- In the left pane, select Visual C# » Code.
- Click Class and in the Name input field, enter JobApplicationUpload.
- From the context menu of JobApplicationUpload.cs, click Rename.
- Change the extension to .ascx.
- Open the newly created file and clear its content and enter the new content.
EXAMPLE: For more information about the contents of the file, refer to class JobApplicationUpload.ascx
from the downloaded sample project.
- Save the file.
- In the Properties pane of the JobApplicationUploadTemplate.ascx file, change the Build Action to Embedded Resource.
In the markup file, you first register the necessary assemblies, so that they can be used in the template. You create a RadFormDecorator, which automatically makes the form elements look more aesthetic. Next, you create a Message control, which will display error and success messages. Then, you create labeled TextBoxes for the user input. You bind form validators, so that the user provides correct input. The labels are fetched from Resources, which are defined in JobsResources.
Create the code-behind
- In the context menu of folder PublicControls, click Add » New Item...
- In the left pane, select Visual C# » Code.
- Click Class and in the Name input field, enter JobApplicationUpload.cs
- Open the file.
- Change the class definition.
- Reference the embedded template.
- Provide properties for the user input.
- Provide references to the Message control.
- In the InitializeControls method, create an event handler for the form submission event.
- Define the JobApplicationUpload_Click method.
- Save the file.
EXAMPLE: For more information about the contents of the file, refer to class JobApplicationUpload.cs
from the downloaded sample project.
In the JobApplicationUpload.cs file, you reference the controls from the JobApplicationUploadTemplate by calling the GetControl method and returning the controls’ values. In the event handler for the form submission event, the control instantiates a JobsManager instance which works with the default provider. It creates a new JobApplication, populates it with the user input and saves it. Finally, it notifies the user for a successful submission of the application by calling Message.ShowPositiveMessage("Your application was submitted successfully");.