Showing posts with label validation. Show all posts
Showing posts with label validation. Show all posts

Monday, March 26, 2012

Tab control question

Does anyone know how to force the user to "stay" in a tab if they try to click another tab? I'm doing validation but don't want them to be able to move to another tab until required fields are filled out.

Thanks,

Doug

http://forums.asp.net/t/1086839.aspx

This post might help. You can intercept the ActiveTabChanged event and decide whether you want to allow the tab to change or not.

Jason


Thanks for that link but I'm still unsure how to prevent the user from getting to another tab. I tried setting the "ActiveTabIndex" within that event and it still goes to the other tab.Tongue Tied

Does anyone have any sample code that would help me?

Thanks!

Doug


Hi Doug,

You may keep the previous selectedIndex in a variable, and assign it back to TabContainer if validation fails.

For instance:

int previousIndex = 0; // variable storing previously selected index
protected void Page_Load(object sender, EventArgs e)
{
previousIndex = TabContainer1.ActiveTabIndex;
}
protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
{
bool validationResult = true;
// compute validationResult
if(!validationResult) // if validation fails
TabContainer1.ActiveTabIndex = previousIndex;
}

Hope this helps.

Saturday, March 24, 2012

TabContainer & TabPanel bug?

On click of a tab, I validate the current tab. If the validation fails, is there a way to keep the current tab selected? I've tried using theActiveTabChangedfunction, but it never goes into the code.

Does anyone know how to select a tab with javascript?

One other thing, when you wrap a TabContainer in an UpdatePanel you get javascript error mesasge when use ajax call within the tab, so this seems to be an issue.

Hi,

Please try this to select a tab
function change() {
??????$find('TabContainer1').set_activeTabIndex(1);
}

Can you show me a small demo about?the?second question ?