none
Why OnValidating method triggering twice when used inside of UserCotnrol? RRS feed

  • Question

  • I have implemented custom validation for my custom control using OnValidating event, and all is working fine. However, if I add my control inside of a UserControl and add this UserControl inside of a TabControl, OnValidating event is triggering twice when I try to navigate to the second tab page. Please find the stack trace details below,

    Please let me know how can I handle this method triggering twice. Is it needed to implement anything in my custom control when used inside the UserCotnrol?

    Thanks,


    Mohanraj G

    Sunday, November 12, 2017 1:45 PM

All replies

  • Hi Mohanraj,

    How’s your code like?

    Based on following document, when we change the focus by using keyboard or using mouse, it will focus events in different order. In addition, if the CausesValidation property is set to false, the Validating and Validated events are suppressed.

    https://msdn.microsoft.com/en-us/library/system.windows.forms.control.validating(v=vs.110).aspx

    Btw, please help us mark a reply as answer if it could help resolve your doubts or issues.

    Your understanding and cooperation will be much appreciated.

     

    Regards,

    Fletcher


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Fletch Zhou Monday, November 13, 2017 7:41 AM
    Monday, November 13, 2017 7:41 AM
  • Hi Fletcher,

    Thanks for your update.

    If i use the CauseValidation property for my custom grid which will not trigger the OnValidating event. I want to trigger the OnValidating event only once while trying navigate to next tab page. I have checked this case in DataGridView control which has working fine. So, i have tested the OnValidating method for DataGridView which has handled by some condition. But i cannot find the solution exactly.

    So can you please help me how can i avoid the OnValidating event triggering twice?

    Thanks,

    Mohanraj


    Mohanraj G

    Tuesday, November 14, 2017 6:33 AM
  • Hi Mohanraj,

    Are you implementing Coded UI testing? It's hard for us to guess what exactly cause this issue without any testing code.

    To access custom control, there is a lot work to do, please refer to this doc to see if it helps:

    Enable Coded UI Testing of Your Controls

     

    Best regards,

    Fletcher  


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Fletch Zhou Wednesday, November 15, 2017 2:23 AM
    Wednesday, November 15, 2017 2:22 AM
  • Hi Fletcher,

    Thanks for your reply

    No i am trying to implement the validation for my grid cell using OnValidating event. In edit mode my cell act as a text box. If i edit the cell then try to click on out of the user control component then i have tried to validate the cell by OnValidating method to commit the value for my grid cells. In this implementation, If i add my grid in CustomControl or Panel or TabControl which has working fine except the UserControl. If i use the UserControl as a parent of my grid, OnValidating method has called twice.

    Let me know how i handle this?

    So, please let me know if you have any query. 

    Thanks


    Mohanraj G

    Wednesday, November 15, 2017 5:44 PM
  • Hi Mohanraj,

    I'm afraid you need to provide a simple demo here, since we can not reproduce this issue, and sorry that we can not guess the real reason for this problem just through your description, unless we try to debug the code.

    So could you please provide a demo with Microsoft OneDrive for testing?

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 16, 2017 5:42 AM
  • Hi Standly & Fletcher,

    I cannot post my sample in this forum. Is it possible to share your id? then i will share my sample from my personal id.

    Thanks,


    Mohanraj G

    Monday, November 20, 2017 3:53 AM
  • We are not allowed to post our email address or personal contact here, so I think it would be better if you could upload your sample on some Cloud like OneDrive, and share us the download link here, then we could download and test it.

    Thanks for your understandings.

     

    Regards,

    Fletcher


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Fletch Zhou Monday, November 20, 2017 5:39 AM
    Monday, November 20, 2017 5:39 AM
  • Hi Fletcher,

    Here i have attached my sample with dlls. Please download the sample from below link,

    https://drive.google.com/open?id=1uObnuwyhYcVuNBF-MiRAmFkdRV


    Replication procedure,

    1.Run the attached sample.

    2. Enter the value "ab" in any cell.

    3. Click on the tab page (page2)

    Issue:

    Message box appears twice

    Thanks,


    Mohanraj G


    • Edited by Mohanmj Tuesday, November 21, 2017 6:12 AM
    Monday, November 20, 2017 1:17 PM
  • Hi Mohanraj,

    I downloaded the project and tested it, it seems the user control that cause this problem comes from the third parties - "Syncfusion".

    it will be more appropriate to ask your question at Syncfusion Forum.

    Thank you for your understanding.

    Regards,

    Stanly

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 21, 2017 6:08 AM
  • Hi Stanly,

    Thanks for your update

    I know that, This issue occurs while using the grid inside of the UserControl. 

    Please look into the attached image in my first post, the flow is differed at second time. The SetActiveControlInternal method calling twice. My query, why that method calling second time and 

    Let me know the reason for this and how can i handle that.

    Thanks,


    Mohanraj G

    Tuesday, November 21, 2017 6:42 AM
  • Hi Mohanraj,

    If the issue is caused by third party control, we really recommend you post the issue on Syncfusion forum as Stanly suggested.

    Also this forum is for Coded UI and web performance testing, and your question seems not related to either of them. We really feel sorry about it.

    Your understanding and cooperation will be grateful.

     

    Best regards,

    Fletcher


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Fletch Zhou Wednesday, November 22, 2017 8:31 AM
    Wednesday, November 22, 2017 8:31 AM
  • Hi Fletcher/ Stanly,

    Still I am facing this issue.

    I have prepared the sample based on our custom control architecture. Please find our custom control details below,

    Sample link: https://drive.google.com/open?id=1p-kcX-fQkhp31zxZ6FxIhcJ5YVkJpabF 

    Note:

    Issue not reproduced in above sample. Just, i have prepared the sample based on our custom control implementation.

    Also, I have debugged the System.WindowsForms.dll. ContainerControl.Unvalidated control getting CustomTableControl and again try to validate for parent control (CustomControl.) using below code,

    internal void UpdateFocusedControl() {

        Debug.WriteLineIf(Control.FocusTracing.TraceVerbose, "ContainerControl::UpdateFocusedControl() - " + this.Name);

     

        // Capture the current focusedControl as the unvalidatedControl if we don't have one/are not validating.

        EnsureUnvalidatedControl(focusedControl);

        Control pathControl = focusedControl;

     

        while (activeControl != pathControl) {

            if (pathControl == null || pathControl.IsDescendant(activeControl)) {

                // heading down. find next control on path.

                Control nextControlDown = activeControl;

                while (true) {

                    Control parent = nextControlDown.ParentInternal;

                    if (parent == this || parent == pathControl)

                        break;

                    nextControlDown = nextControlDown.ParentInternal;

                }

     

                Control priorFocusedControl = focusedControl = pathControl;

                EnterValidation(nextControlDown);

    }

    So, please request to avoid this validation happening for this  two controls(CustomTableControl and CustomControl).

    Please suggest me to resolve this issue which will be more helpful to fix this issue for my custom control.

    Thanks,


    Mohanraj G


    • Edited by Mohanmj Tuesday, December 12, 2017 2:09 AM
    Tuesday, December 12, 2017 1:42 AM