דף הבית  >> 
 >> 

הרשם  |  התחבר


Validation in TabContainer 

מאת    [ 28/12/2010 ]

מילים במאמר: 520   [ נצפה 2216 פעמים ]

You may have faced a common problem were you want to put a validation controls inside a TabContainer. and you want to add a postback button (e.g. Save button, which will be used as an example) to validate all the controls, but the problem, if you have an invalid control, is how to select the correct Tab, based on the Validation status (you may want to select the first invalid Tab).

I'm talking about when you have the same ValidationGroup in all the controls which are spread through multiple tabs, and ofcourse you have the Save button with the same ValidationGroup.

First thing I'll try to do is to remove the validation group from the Save button.
Then I'll do the Validation in the server side :

Page.Validate();

and then I'll ask if all the conrtols in the page are valid,and if so I'll Save the data :

if (Page.IsValid)
{
            Save();
}


well, this can be great if it works as I expect, but it didn't.
The active tab was the last one when I clicked the Save button.

so I tried to change the tab accordingly, for that I had to add methods to check if the data in each tab is valid .

example:
private bool IsTab1DataValid()
{
        if (TextBox1.Text.Length == 0)
            return false;
        return true;
}


and then in the Save() method I did:

protected void Save()
{
        Page.Validate();
        if ( ! IsTab1DataValid())
        {
            tabContainer.ActiveTab = TabPanel1;
            return;
        }
        if ( ! IsTab2DataValid())
        {
           
tabContainer.ActiveTab = TabPanel2;
            return;
        }
        Save();
}


[Note]: you may assign different Validation group for different tabs, then you can use Page.Validate("ValidationGroupForTab1"); and so on ... instead of previous methods

 

it should be Ok now, but if you have ValidatorCallout in the Page then it's not Ok, the ValidatorCallout will be misplaced if you switch tabs (Bug?).

what to do now?

well, it's about the time for some JavaScript.

first thing Remove the Page.Validate(); line from the Save() method, and then we need to place this script to validate the page in client side:



That's it.

Note: if you have the TabContainer inside an UpdatePanel, then you need to validate the page after each request:



Next: I'll try to do it all in Javascript.

 

validation in ajaxtoolkit tabcontainer

,Javascript,asp,asp.net,ajax,Validate




מאמרים חדשים מומלצים: 

חשבתם שרכב חשמלי פוטר מטיפולים? תחשבו שוב! -  מאת: יואב ציפרוט מומחה
מה הסיבה לבעיות האיכות בעולם -  מאת: חנן מלין מומחה
מערכת יחסים רעילה- איך תזהו מניפולציות רגשיות ותתמודדו איתם  -  מאת: חגית לביא מומחה
לימודים במלחמה | איך ללמוד ולהישאר מרוכז בזמן מלחמה -  מאת: דניאל פאר מומחה
אימא אני מפחד' הדרכה להורים כיצד תוכלו לנווט את קשיי 'מצב המלחמה'? -  מאת: רזיאל פריגן פריגן מומחה
הדרך שבה AI (בינה מלאכותית) ממלאת את העולם בזבל דיגיטלי -  מאת: Michael - Micha Shafir מומחה
ספינת האהבה -  מאת: עומר וגנר מומחה
אומנות ברחבי העיר - זרז לשינוי, וטיפוח זהות תרבותית -  מאת: ירדן פרי מומחה
שיקום והעצמה באמצעות עשיה -  מאת: ילנה פיינשטיין מומחה
איך מורידים כולסטרול ללא תרופות -  מאת: קובי עזרא יעקב מומחה

מורנו'ס - שיווק באינטרנט

©2022 כל הזכויות שמורות

אודותינו
שאלות נפוצות
יצירת קשר
יתרונות לכותבי מאמרים
מדיניות פרטיות
עלינו בעיתונות
מאמרים חדשים

לכותבי מאמרים:
פתיחת חשבון חינם
כניסה למערכת
יתרונות לכותבי מאמרים
תנאי השירות
הנחיות עריכה
תנאי שימוש במאמרים



מאמרים בפייסבוק   מאמרים בטוויטר   מאמרים ביוטיוב