how to get the button name in the formevents_submit event - InfoPath Dev
in

InfoPath Dev

how to get the button name in the formevents_submit event

Last post 09-29-2011 07:23 PM by DhavalR. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 06-17-2008 09:41 AM

    how to get the button name in the formevents_submit event

    Hi, I have 2 buttons in the browser base infopath form that perform different tasks. They all close the form after clicked, but need to run some codes differently before closes. I found that both of the buttons will hit the formEvents_submit routine (I set them to use submit in the button property box). Now if I can tell which button triggered this event, all will be set. Question: is there any way I can tell from the code which button was clicked? In asp.net, we would cast the sender object to a button class and get the button name. But I don't know how to do similar in InfoPath.

    Thanks for any help

  • 06-17-2008 04:11 PM In reply to

    Re: how to get the button name in the formevents_submit event

    A few ways:

    1. Add a field (can be in a secondary XML file) which is populated by rules or code on button click identifying the button which was clicked. Then check this value in the submit code.

    2. The button click event handler can pass a parameter to the submit function to identify which button was clicked.

  • 06-18-2008 06:41 AM In reply to

    Re: how to get the button name in the formevents_submit event

    Would you mind showing me how to pass a parameter in the button click event handler? (Code snippet or a link)

    Thank you very much.

  • 06-19-2008 10:14 AM In reply to

    Re: how to get the button name in the formevents_submit event

    You have some sort of click event handler that gets called when you click the button... the code inside there is calling your submit code, right... so add a parameter to the submit function and pass it the button name to it:

    pseudo code, not actual code: 

    ButtonEventHandler(...)
    {
        Submit("Button1");
    }

    Submit(string ButtonName)
    {
        if(ButtonName == "Button1")
        {
        }
    }

  • 06-19-2008 01:09 PM In reply to

    Re: how to get the button name in the formevents_submit event

    Well, I don't think that work in my scenario:

    I have an event hander that was generated itself when I chose to use "Submit" action and "perform custom action using code" and clicked "Edit Code":

    public void FormEvents_Submit(object sender, SubmitEventArgs e)

     {

    ....

    }

    Now I have 2 buttons on the form both defined that way, when I click any of the 2 buttons, they all hit this routine (above), I want to know which button was clicked to hit this routine so that I will do different task. How should I do that by passing in a parameter?

    Thanks. 

     

    Please don't tell me to use rules, as that won't work in my case as well. 

     

  • 06-23-2008 03:20 PM In reply to

    Re: how to get the button name in the formevents_submit event

    Actually, I will tell you to use rules -- but not like you are thinking.

    Rules run before code does. Therefore, you can have a field (can be in a secondary data source -- .xml file, whatever), that is used to identify which button was pressed. The first rule on each button sets a value on this field. Then when you enter the FormEvents_Submit() function, you get the value from this secondary data source field and it will tell you which button was pressed.

  • 12-17-2008 01:51 AM In reply to

    • Neeraj
    • Not Ranked
    • Joined on 12-17-2008
    • Posts 1

    Re: how to get the button name in the formevents_submit event

    I am facing the same issue.. Did you get any solution regarding having two submit button on an infopath from and doing different task on click of any of these submit button? basicaaly any API that tells which button was clicked..

  • 09-30-2010 12:06 PM In reply to

    Re: how to get the button name in the formevents_submit event

    I know this is much later but maybe it can help someone later down the road.

    The click event args provide the button ID thru e.ControlID... unfortunately, there does not seem to be a way to extract the button label (of .Text value in regular C#).

    Josée Sévigny
  • 09-30-2010 05:58 PM In reply to

    Re: how to get the button name in the formevents_submit event

    No, I don't believe there is a way to access the button text through code.  Why do you need it?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 09-29-2011 07:23 PM In reply to

    Re: how to get the button name in the formevents_submit event

    Instead of an Infopath button can I submit form using ASP.NET button because my form is in XmlFormView control. If yes then how to do that ?
Page 1 of 1 (10 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.