To update the page status with a percentage using the cms:AsyncControl
in Kentico, you can follow these steps:
- Add the
cms:AsyncControl
to your page or template where you want to display the progress:
<cms:AsyncControl ID="AsyncControl" runat="server" OnStart="AsyncControl_Start" OnProgress="AsyncControl_Progress" OnComplete="AsyncControl_Complete" />
- In your code-behind file, handle the
OnStart
,OnProgress
, andOnComplete
events of thecms:AsyncControl
:
protected void AsyncControl_Start(object sender, EventArgs e)
{
// Perform any necessary initialization tasks
}
protected void AsyncControl_Progress(object sender, CMSEventArgs e)
{
// Calculate the progress percentage
int progress = CalculateProgress();
// Update the page status with the progress percentage
AsyncControl.SetStatusMessage("Updating page... " + progress + "%");
}
protected void AsyncControl_Complete(object sender, EventArgs e)
{
// Update the page status to indicate completion
AsyncControl.SetStatusMessage("Page updated successfully");
}
private int CalculateProgress()
{
// Calculate the progress based on your logic
// Return the progress percentage as an integer value (0-100)
return 50;
}
In this example, the AsyncControl_Start
event handler is triggered when the async operation starts. You can perform any necessary initialization tasks at this point.
The AsyncControl_Progress
event handler is triggered periodically during the async operation. Within this handler, you can calculate the progress percentage based on your logic. Update the page status using the AsyncControl.SetStatusMessage
method, appending the progress percentage.
The AsyncControl_Complete
event handler is triggered when the async operation is complete. You can update the page status to indicate successful completion.
The CalculateProgress
method is a placeholder where you can implement your own logic to calculate the progress percentage based on the actual progress of your async operation.
Note that the cms:AsyncControl
control relies on JavaScript and AJAX to update the page asynchronously. Ensure that the required scripts and libraries are included on your page for the cms:AsyncControl
to function correctly.
Make sure to customize the code according to your specific requirements, including the logic to calculate progress and any additional actions that need to be performed during the async operation.
Additionally, you can customize the appearance of the page status by applying CSS styles or using the available options provided by the cms:AsyncControl
.