I'm in the process of developing an ASP site that requires users to fill out a form. I have incorporated textboxes, dropdown lists, and utilized Bootstrap 4 for styling purposes. The entire content is enclosed within an update panel to ensure a responsive user experience without necessitating a full postback.
Upon submission of the form, I conduct a check to ascertain if any of the fields, be it textboxes or dropdown lists, are left empty. In such instances, I refrain from inserting data into the database and mark the empty fields by adding "is-invalid" to their CssClass property.
Control.CssClass += " is-invalid";
Initially, everything functions as intended with the empty fields displaying in red.
However, when the user proceeds to fill in the formerly empty fields and clicks submit again, the fields persist in appearing red despite my attempts to remove the "is-invalid" class by replacing it with an empty string.
Control.CssClass.Replace(" is-invalid", "");
My query revolves around why the red highlighting fails to vanish. If altering the CssClass via the CodeBehind works seamlessly during append operations, then why does the removal operation fall short?
PS.: I am aware that employing JavaScript could offer a solution, but I strongly prefer maintaining the entirety of the validation process within the CodeBehind rather than splitting it between C# (.cs) and JavaScript functions. Nevertheless, if resolving this issue becomes unattainable solely using CodeBehind, I may resort to leveraging JavaScript, though I remain hopeful for a resolution utilizing C#.