In this blog, we will see how we can create a circular progress bar in ASP.NET just by applying style.

Thus, let's go.

Let's take an example that we need to show the active users on a circular progress bar. For it, we will take a div and apply style to make it circular.
  1. <div id="circularProgess" class="circularprogress background" runat="server">
  2. <div id="ProgressText" class="overlay" runat="server"></div>
  3. </div>
Add the style, mentioned below.
  1. <style>
  2. .background {
  3. background-image: linear-gradient(<%= Val1 %>, <%= ColorCode %> 50%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0)), linear-gradient(<%= Val2 %>, #AC2D36 50%, #ffffff 50%, #ffffff);
  4. }
  5. /* -------------------------------------
  6. * Bar container
  7. * ------------------------------------- */
  8. .circularprogress {
  9. float: left;
  10. margin-left: 50px;
  11. margin-top: 30px;
  12. position: relative;
  13. width: 180px;
  14. height: 180px;
  15. border-radius: 50%;
  16. }
  17. /* -------------------------------------
  18. * Optional centered circle w/text
  19. * ------------------------------------- */
  20. .circularprogress .overlay {
  21. position: absolute;
  22. width: 130px;
  23. height: 110px;
  24. color: white;
  25. background-color: #CF5760;
  26. border-radius: 50%;
  27. margin-left: 25px;
  28. margin-top: 23px;
  29. text-align: center;
  30. line-height: 90px;
  31. font-size: 35px;
  32. padding-top: 20px;
  33. }
  34. </style>

In the background style, I have added val1 and val2, where I will assign from .cs page, so we can make a dynamic circular progress bar. Add the properties and methods, mentioned below in .cs file.
  1. private string val1 = "90deg";
  2. public string Val1
  3. {
  4. get { return val1; }
  5. set { val1 = value; }
  6. }
  7. private string val2 = "90deg";
  8. public string Val2
  9. {
  10. get { return val2; }
  11. set { val2 = value; }
  12. }
  13. private string colorCode = "#ffffff";
  14. public string ColorCode
  15. {
  16. get { return colorCode; }
  17. set { colorCode = value; }
  18. }
  19. protected void Page_Load(object sender, EventArgs e)
  20. {
  21. ProgressText.InnerText = "0%";
  22. CalculateActiveUsersAngle(75);
  23. }
  24. private void CalculateActiveUsersAngle(int TotalUser)
  25. {
  26. //int TotalUser = 50;
  27. if (TotalUser == 0)
  28. {
  29. Val2 = "90deg";
  30. Val1 = "90deg";
  31. ColorCode = "#ffffff";
  32. }
  33. else if (TotalUser < 50 && TotalUser > 0)
  34. {
  35. double percentageOfWholeAngle = 360 * (Convert.ToDouble(TotalUser) / 100);
  36. Val2 = (90 + percentageOfWholeAngle).ToString() + "deg";
  37. Val1 = "90deg";
  38. ColorCode = "#ffffff";
  39. }
  40. else if (TotalUser > 50 && TotalUser < 100)
  41. {
  42. double percentage = 360 * (Convert.ToDouble(TotalUser) / 100);
  43. Val1 = (percentage - 270).ToString() + "deg";
  44. Val2 = "270deg";
  45. ColorCode = "#AC2D36";
  46. }
  47. else if (TotalUser == 50)
  48. {
  49. Val1 = "-90deg";
  50. Val2 = "270deg";
  51. ColorCode = "#AC2D36";
  52. }
  53. else if (TotalUser >= 100)
  54. {
  55. Val1 = "90deg";
  56. Val2 = "270deg";
  57. ColorCode = "#AC2D36";
  58. }
  59. ProgressText.InnerText = TotalUser + "%";
  60. }
CalculateActiveUsersAngle() method will calculate and show the exact angle .You can assign the angle if you want to CalculateActiveUsersAngle() method. For this example, I have assigned 75, so circular progress will display 75% on the radial. It will display, as shown below.

Hope you understood and enjoyed.