ASP.NET Major problem with validation in Tab Control
Posted on 2009-12-28
I have a AJAX tab control that is embedded in an update panel. Each panel holds a user control and forward and back buttons to go through the panel like a wizard. Each user control has validation controls to check the proper entry of data. If the data is valid the user should be able to move to the next tab. At the beginning only the first tab in enabled. As the user goes along always the next tab will be enabled when the data is valid. The user can go back via the buttons or click on the tabs.
(As a side note: On each tab change the data is written to a data base to be able to recover from any crashes. The tab that is going to be dispayed will load the data from the database, too.)
My problem is the proper validation. If the user uses the button I set the ActiveTabIndex property of the tab control. Besides the onload events of the page and the user controls it fires the validation controls. If the user clicks a tab the ActiveTabChanged event is catched in the main page code. I can react to it, update the data and the panel is changed, but this time no validation control is fired; only the load events are called.
So I don't know how to trigger the validation controls. Is there a way to fire all of the validation controls on a page at once per code? Is there a way to tell the tab control to trigger the validation controls on an ActiveTabChanged event?
I'm thinking at the moement to do the following workaround: Do all the validation "by hand" in the code. I can define my validation functions in the user control and then call those functions from the main page during the data handling. I just need to find a way to "cancel" the ActiveTabChanged event, so that the user stays on the same tab if the entered data is not valid.
Can anybody help?