I have an asp.net page, some of its controls are created dynamically, these controls are one of the following; textbox, calendar, or dropdownlist.
These controls in some cases, should be validated based on flag read from db?
Is there any way to validate dynamically created controls?
I got a solution for that problem. One of the main problems that I had with this page that it’s ajax-enabled and I need to validate dynamically created controls.
My solution and it works properly, while creating the Control, I added an input attribute to it markes it as it is required or not, and another attribute that marks it as it is a field to be validated or not?
Using Javascript, I go through all input tags with attribute ‘dynamic control’ and based on ‘to validate attribut’, I validate it or not. Simple, right?
Sample Code: While control creating, mark it like the following
JavaScript code
Of course, you can call that code while clicking the required button.