Wednesday, March 21, 2012

TabContainer and Validator

I'm new to the toolkit... Can you use RequiredFieldValidator to validate a textbox when the user clicks on a different TabPanel in the TabContainer? I imagine that you can write your own JS. Thoughts?

Thanks!!!

Hi,

According to my understanding to your question, you are trying to prevent the other TabPanel from being actived if current TabPanel has validators that fail to validate. Isn't it?

As far as I know, the TabContainer doesn't expose an event that fires before the active panel is changed. So, you may try an alternative method. The basic idea is as follows:

1. Add an activeTabChanged event handler to the TabContainer
2. When a tabPanel is actived, save its index in a global variable
3. In the activeTabChanged handler, check if all Validators in previous tabPanel are valid. If not, set current active index to the index stored in global variable.

You may have the following code:

function pageLoad() {
tc = $find("TabContainer1");
tc.add_activeTabChanged(onChanged);
}

var index = 0;

function onChanged(sender, e) {
tc = $find("TabContainer1");
if( !Page_Validators[0].isvalid ){ // I assume validators[0] is in previous panel here. For practical usage, you may have to implement a strategy to organize validators in different panels
tc.set_activeTabIndex(index);
}
else{
index = tc.get_activeTabIndex(index);
}
}

Though this approach is not that straight, still hope this can helps.

No comments:

Post a Comment