Hi,
In this scenario have a TabContainer with 8 TabPages.
Each TabPage contains 1 UpdatePanel.
Each UpdatePanel contains 5 RadioButtonLists with corresponding RequiredFieldValidators
On each TabPage there is a series of questions that need to be answered by selecting a option from each of the RadioButtonLists. If the user decides to continue to the next TabPage, he will click on the next TabPage's header. The following happens:
1. The clicked TabPage is displayed.
2. An OnClientActiveTabChange is fired to set off a javascript postback.
3. The RequiredFieldValidators checks if all the RadioButtonList is answered.
If everything is answered, the postback fires, the answers is saved server-side in a database and the user is allowed to continue.
If everything is not answered, the postback is canceled.
This works perfectly. The only flaw here is the fact that the TabContainer displays the next TabPagebefore the RequiredFieldValidators validate the RadioButtonLists. This gives me the problem of even though the user didn't answer all his questions on the previous TabPage, he can now view and answer the questions on the next TabPage. Is there a way I can determine the result of a RequiredFieldValidator on the clientside, so that I can switch the user back to the TabPage which isn't completed yet?
Part of your issue is that Client Script on the Validators do not work inside UpdatePanels (see last bullet point here:http://blogs.visoftinc.com/archive/2007/09/23/asp.net-ajax--updatepanel-not-working--common-problems.aspx) There is a link to UpdatePanel friendly validators on that page as well.
To determine if the validator is valid, check IsValid on the validator client side.
Hope this helps.
-Damien
Seehttp://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx for the way to get your validators to work inside an updatepanel. It is probably not a tab issue at all.
Thanks for the reply.
I have found the selution to my problem. All I had to do was to intercept the onpropertychange event of the RequiredFieldValidator, filter out the irrelevant properties and test if 'isvalid' was true or false. If there are any questions regarding this situation, please don't hesitate to e-mail me.
function SimPostback(sender,args)//Registered on the TabContainer's onclientactivetabchanged event
{
TabContainer = sender;
selectedIndex = (sender.get_activeTabIndex());
if(selectedIndex != LastSelectedTab)
{
document.getElementById('ctl00$cphForm$tcMainTabContainer$ctl00$Button'+(LastSelectedTab)).click();
}
}
function RequiredFieldValidator_CheckValid(RFVObj)//Register on the RequiredFieldvalidator's onpropertychange event
{
var rfv = document.getElementById(RFVObj);
var EventName = event.propertyName;
if(EventName =="isvalid")
{
if(rfv.attributes["isvalid"].value =='false')
{
TabContainer.set_activeTabIndex(LastSelectedTab);
}
}
}
No comments:
Post a Comment