This is a migrated thread and some comments may be shown as answers.

Validation Of TabPage on TabSelecting

9 Answers 447 Views
Tabstrip (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ajay
Top achievements
Rank 1
Ajay asked on 16 Feb 2010, 08:46 AM

HI,
    I have one issue regarding RadTabStrip. I have created two pages(Page 1 and Page 2) in RadTabstrip.In both the pages i have added two Radio Buttons and One Text box.Now I have subscribed Validating event of Text boxes of both the pages. I also have subscribed TabSelecting event of RadTabStrip.
                                                  Now in my scenario if validation of current Text Box is not done,I should not be able to select different tabPage.so to achieve this i have made  args.Cancel = true; this statement in TabSelecting Event.

C# Code :

private void radTabStrip1_TabSelecting(object sender, Telerik.WinControls.UI.TabCancelEventArgs args)
        {
            if (!Valid)
            {
                args.Cancel = true;
            }
        }

Here Valid is globla variable showing i need to stop tabChange.

Problem :

Suppose now i am on Page 1 and entered some Invalid entry in TextBox and I click on  page 2. Validation fires from Text Box and force me to be on page 1. Here Page 2 is not selected.This is fine for me,But now if i made Valid Entry in Text Box then I am able to change tab but not able to click( or change) Raido button on Page 1. Here I am suppose to change or select Radio button on same page in case of valid entry in Text Box.

9 Answers, 1 is accepted

Sort by
0
Dobry Zranchev
Telerik team
answered on 17 Feb 2010, 10:11 AM
Hello Ajay,

Thank you for writing. We could not reproduce the issue. Could you modify the attached example to reproduce that issue. Thank you in advanced. If you have any other questions feel free to ask.

Regards,
Dobry Zranchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ajay
Top achievements
Rank 1
answered on 17 Feb 2010, 12:59 PM

My Finding is that without using MessageBox it runs fine but wiht messageBox it loses focus and not able to select Radio button. Please revarify through my above given details.




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication10
{
    public partial class Form1 : Form
    {
        private bool valid;
       
        public Form1()
        {
            InitializeComponent();
        }

        private void radTabStrip1_TabSelecting(object sender, Telerik.WinControls.UI.TabCancelEventArgs args)
        {
            if (!valid)
            {
                args.Cancel = true;
            }
        }

        private void radTextBox1_Validated(object sender, EventArgs e)
        {
       
        }

        private void radTextBox2_Validated(object sender, EventArgs e)
        {
           
        }

        private void radTextBox2_Validating(object sender, CancelEventArgs e)
        {
            valid = true;
            if (radTextBox2.Text.Length > 2)
            {
                e.Cancel = true;
                MessageBox.Show("Error: Length cant be more than 2","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                radTextBox2.SelectAll();
                valid = false;
            }
        }

        private void radTextBox1_Validating(object sender, CancelEventArgs e)
        {
            valid = true;
            if (radTextBox1.Text.Length > 2)
            {
                e.Cancel = true;
                MessageBox.Show("Error: Length cant be more than 2", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                radTextBox1.SelectAll();
                valid = false;
            }
        }

       
    }
}

0
Dobry Zranchev
Telerik team
answered on 17 Feb 2010, 03:00 PM
Hi Ajay,

Thank you for contacting us. That's expected behavior. Every-time when you lost focus, the event Validating is fired and you can cancel validation in your code and leave RadTextBox control in edit mode. The message box has no meaning.

You can read more about validation here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.validating.aspx

Kind regards,
Dobry Zranchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ajay
Top achievements
Rank 1
answered on 09 Mar 2010, 11:13 AM
Hi,
    I know The message box has no meaning, But in our application it is required to show messgebox type of prompt to user.This functionality can be achieved in Windows TabContro by using Deseleting event of TabControl. May i know is there any event similar to
Deselecting event or any other property or function  or some work around to achieve this functionality.

Thanks,
Ajay
0
Dobry Zranchev
Telerik team
answered on 09 Mar 2010, 03:46 PM
Hi Ajay,

You should check witch tab is clicked and validate according to that. If the selected tab is the first tab, you need to validate according to the text box that is in the second one and reverse. Please look at the following code:

private void radTabStrip1_TabSelecting(object sender, Telerik.WinControls.UI.TabCancelEventArgs e)
{
    if (e.TabItem == this.tabItem2)
    {
        if (radTextBox1.Text.Length > 2)
        {
            e.Cancel = true;
            MessageBox.Show("Error: Length cant be more than 2", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            this.radTextBox1.Focus();
            radTextBox1.SelectAll();
            valid = false;
        }
    }
    else if (e.TabItem == this.tabItem1)
    {
        if (radTextBox2.Text.Length > 2)
        {
            e.Cancel = true;
            MessageBox.Show("Error: Length cant be more than 2", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            this.radTextBox2.Focus();
            radTextBox2.SelectAll();
            valid = false;
        }
    }
}

I hope that this helps.

Sincerely yours,
Dobry Zranchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ajay
Top achievements
Rank 1
answered on 10 Mar 2010, 09:49 AM
Hi,
    as per your suggestion, I have tried it but, It also did n't work.Here main problem is if we set e.Cancel to true in selecting event, Now if I made a valid entry on the same page then controls are not working (or active ie. Radio button in Previous example), thats my finding is. If I have not understand your solution update me the last code which i have sent you in earlier response.

Thanks,
Ajay
0
Dobry Zranchev
Telerik team
answered on 10 Mar 2010, 01:18 PM
Hello Ajay,

Thank you for contacting us back. May be I did not understand you. Could you provide an example?

Sincerely yours,
Dobry Zranchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ajay
Top achievements
Rank 1
answered on 12 Mar 2010, 08:43 AM
Hi.
    Actully i want to achive functionality in TabStrip, which i have achived by windows TabControl. 
 
   Objective:  If i made invalid entry user should not be able to click any where and he will be on the validating control.
   Step to reporduce the issue :
                           1. after making Invalid entery click on other tab, It should prompt message (MessageBox it is required for application).
                           2. Now make some valid entry and change other control like Radio button,Combo Box (But not Text Box) on page.
                           3. Here after message prompt if user made valid entry. User is not able to change control on page.

Hope you would have understood my concern.
Note : Giving you the code which i have done with Windows TabControl.
Regards,
Ajay 
  
                           
using System;  
using System.Collections.Generic;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.Linq;  
using System.Text;  
using System.Windows.Forms;  
using Telerik.WinControls.UI;  
 
namespace WindowsFormsApplication44  
{  
    public partial class Form1 : Form  
    {  
        public Form1()  
        {  
            InitializeComponent();  
        }  
 
        bool cancel = true;  
        private void tabControl1_Deselecting(object sender, TabControlCancelEventArgs e)  
        {  
            TabControl tc = (TabControl)sender;  
            if (tc.SelectedIndex != 0)  
            {  
                return;  
            }  
            e.Cancel = cancel;  
            cancel = false;  
        }  
 
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)  
        {  
            if (this.tabControl1.SelectedIndex != 0)  
            {  
                return;  
            }  
            e.Cancel = cancel;  
            cancel = false;  
        }  
 
        private void textBox2_Validating(object sender, CancelEventArgs e)  
        {  
            if (textBox2.Text.Length == 2)  
            {  
                MessageBox.Show("Error");  
                cancel = true;  
                textBox2.Focus();  
                textBox2.SelectAll();  
            }  
            else  
            {  
                cancel = false;  
            }  
        }  
    }  
}  
 
0
Dobry Zranchev
Telerik team
answered on 12 Mar 2010, 01:44 PM
Hi Ajay,

Thanks for your feedback. We will decide later whether we will add that functionality (Deselecting, Deselected events).

The right work-around is to use TabSelecting event of RadTabStrip and check the argument for the selected TabItem, the currently selected item, and validate accordingly.

If this does not help, please send us a sample project and I will update it.

Best wishes,
Dobry Zranchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Tabstrip (obsolete as of Q2 2010)
Asked by
Ajay
Top achievements
Rank 1
Answers by
Dobry Zranchev
Telerik team
Ajay
Top achievements
Rank 1
Share this question
or