Force validation event - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Force validation event

Last post 06-28-2011 01:40 AM by mads68. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 06-21-2011 06:33 AM

    • mads68
    • Not Ranked
    • Joined on 06-21-2011
    • Posts 2

    Force validation event

    Hi,

     I have made som C# validation in my Infopath form on two fields. Basicly the validation looks like this:

    public void Kontonr_Validating(object sender, XmlValidatingEventArgs e)
    {
        if (validate if the combo of the fields Kontonr and Kundenr is not correct)
           e.reporterror(e.Site, false, "Combo of the fields is not correct)

    }

    public void Kundenr_Validating(object sender, XmlValidatingEventArgs e)
    {
        if (validate if the combo of the fields Kontonr and Kundenr is not correct)
           e.reporterror(e.Site, false, "Combo of the fields is not correct)

    }

    When i enter some text in the first field (Kontonr) and leave it and the field "Kundenr" is empty, it will leave an error, which is ok.
    When i enter some text in the second field (Kundenr) and leave and the combo of the fields is right, then the field "Konto" still have an error message.

    In the end of public void Kundenr_Validating I would like to call public void Kontonr_Validating so that field is validated again, but i dont know what args to call it with. Can anyone help me?

    Regards
    Mads

  • 06-26-2011 09:45 PM In reply to

    I would suggest using validation rules instead of code if at all possible.  They will be automatically rerun for all fields any time any field value changes, so they will behave the way you're describing and won't have all the drawbacks of code.

    If you absolutely have to use code, you can do something like this:

    public void Kontonr_Validating(object sender, XmlValidatingEventArgs e)
    {
       ValidateKontonrKundenr();
    }

    public void Kundenr_Validating(object sender, XmlValidatingEventArgs e)
    {
       ValidateKontonrKundenr();
    }

    public void ValidateKontonrKundenr()
    {
         XPathNavigator kontonr = MainDataSource.CreateNavigator().SelectSingleNode("xpath", NamespaceManager);
         XPathNavigator kundenr = MainDataSource.CreateNavigator().SelectSingleNode("xpath", NamespaceManager);

         if(validate if the combo of fields Kontonr and Kundenr is not correct)
         {
              Errors.Add(kontonr, "kontonr", "Combo of the fields is not correct");
              Errors.Add(kundenr, "kundenr", "Combo of the fields is not correct");
         }
         else
         {
              // This will throw an exception if no errors are currently set, but we can ignore it
              try
              {
                   Errors.Delete("kontonr");
                   Errors.Delete("kundenr");
              }
              catch {}
         }

    }

     

     

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-26-2011 10:01 PM In reply to

    There were a few changes I forgot to make before I hit post.  Please check the updated code in the forum thread.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-28-2011 01:40 AM In reply to

    • mads68
    • Not Ranked
    • Joined on 06-21-2011
    • Posts 2

    Hi Jimmy,

    Thank you for your answer. It worked!

    Regards Mads

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.