Increased iFrame load to avoid validation errors

Task:

I have a .NET user control and I use an iFrame inside it. I have several instances (there can be any number) of this control (with an iFrame in it) on the page. I have to load all controls every time one control state changes. The control has required fields.

I have a button that switches to another screen, and because every time I load all the controls, it takes a considerable amount of time to load them. The user tries to fill in all the required fields and click the next button on this instance, even if the user has completed all the required fields, and the control (with iframe) has not fully loaded, it causes a validation error.

Note. All of the above is in JavaScript, not server side.

What I tried:

  • I tried to show the modal div until it loads, but I cannot apparently fix the exact loading time, and the next button can be clicked.

  • I tried the timeout of the validation function, but it works sporadically since the download is not final.

  • I tried to have a counter to see how many controls were loaded, to check the common controls, and only then letting the authentication function run, again finally downloading it, does not help.

I know this can be done differently, but due to the tremendous effort and time, we need to roll with the existing method and have to solve the problem. Can someone please suggest any pointers / workarounds for the problem.

+5
source share
1 answer

I have it fixed. The fix I believe is a trick, but I didn't know another way.

I took approach 3, as mentioned above. You have a timeout from 1 ms, and the counter increments in that timeout, i.e.

setTimeout(function() { counter++; }, 1); 

I have one more counter of my verification code to delay it for 1 ms and check the condition if the counter is equal to all available controls, if not check again until the condition is false. Otherwise, continue.

  function validate() { if (counter != total number of frames) { setTimeout(function() { validate(); }, 1); return false; } ... } 

Thanks to everyone for your materials, it helped a lot. I hope this will be the last solution for such issues.

0
source

All Articles