EventHandler for Custom Toolbar Button

N

Nick Head

I have a custom toolbar button defined in my manifest file:

<xsf:toolbar name="Form toolbar" caption="Form toolbar">
<xsf:button caption="test Button" name="btnTest"></xsf:button>
</xsf:toolbar>

How do I hook up a managed event handler for when this button is pressed? I know that button elements can have action atributes e.g.

<xsf:button
name="btnTest"
action="xCollection::insert" >

But how do I map that to an eventhandler in my C# class? I tried just running my project with the following event handler, but InfoPath just gave me an error:
"InfoPath cannot open the selected form because of an error in the form's code. The form template has an invalid event handler: OnBtnTestClick."

[InfoPathEventHandler(MatchPath="btnTest", EventType=InfoPathEventType.OnClick)]
public void OnBtnTestClick(DocReturnEvent e)
{
thisXDocument.UI.Alert("pressed!");
e.ReturnStatus = true;
}

Any ideas?

TIA
Nick
 
S

StefanO-nl

You almost did everything right, except for the parameter type of your eventhandler; it should be DocActionEvent, so this should be your code:

[InfoPathEventHandler(MatchPath="btnTest", EventType=InfoPathEventType.OnClick)]
public void OnBtnTestClick(DocActionEvent e)
{
thisXDocument.UI.Alert("pressed!");
e.ReturnStatus = true;
}

This is how I've made it work (and I didn't use the action-attribute in the xsf).
 
N

Nick Head

Perfect! Thanks for your response.

Although I guess I should have RTFM a bit more thoroughly...


StefanO-nl said:
You almost did everything right, except for the parameter type of your eventhandler; it should be DocActionEvent, so this should be your code:

[InfoPathEventHandler(MatchPath="btnTest", EventType=InfoPathEventType.OnClick)]
public void OnBtnTestClick(DocActionEvent e)
{
thisXDocument.UI.Alert("pressed!");
e.ReturnStatus = true;
}

This is how I've made it work (and I didn't use the action-attribute in the xsf).

Nick Head said:
I have a custom toolbar button defined in my manifest file:

<xsf:toolbar name="Form toolbar" caption="Form toolbar">
<xsf:button caption="test Button" name="btnTest"></xsf:button>
</xsf:toolbar>

How do I hook up a managed event handler for when this button is pressed? I know that button elements can have action atributes e.g.

<xsf:button
name="btnTest"
action="xCollection::insert" >

But how do I map that to an eventhandler in my C# class? I tried just running my project with the following event handler, but InfoPath just gave me an error:
"InfoPath cannot open the selected form because of an error in the form's code. The form template has an invalid event handler: OnBtnTestClick."

[InfoPathEventHandler(MatchPath="btnTest", EventType=InfoPathEventType.OnClick)]
public void OnBtnTestClick(DocReturnEvent e)
{
thisXDocument.UI.Alert("pressed!");
e.ReturnStatus = true;
}

Any ideas?

TIA
Nick
 
E

Eric

Hi Nick,

I'd be very grayeful if you could indicate a way to achieve the same goal,
i.e. bind an event handler to a custom toolbar option, yet using jscript as
opposed to C# managed code.

Many thanks in advance,

Eric

Nick Head said:
Perfect! Thanks for your response.

Although I guess I should have RTFM a bit more thoroughly...


StefanO-nl said:
You almost did everything right, except for the parameter type of your eventhandler; it should be DocActionEvent, so this should be your code:

[InfoPathEventHandler(MatchPath="btnTest", EventType=InfoPathEventType.OnClick)]
public void OnBtnTestClick(DocActionEvent e)
{
thisXDocument.UI.Alert("pressed!");
e.ReturnStatus = true;
}

This is how I've made it work (and I didn't use the action-attribute in the xsf).

Nick Head said:
I have a custom toolbar button defined in my manifest file:

<xsf:toolbar name="Form toolbar" caption="Form toolbar">
<xsf:button caption="test Button" name="btnTest"></xsf:button>
</xsf:toolbar>

How do I hook up a managed event handler for when this button is pressed? I know that button elements can have action atributes e.g.

<xsf:button
name="btnTest"
action="xCollection::insert" >

But how do I map that to an eventhandler in my C# class? I tried just running my project with the following event handler, but InfoPath just gave me an error:
"InfoPath cannot open the selected form because of an error in the form's code. The form template has an invalid event handler: OnBtnTestClick."

[InfoPathEventHandler(MatchPath="btnTest", EventType=InfoPathEventType.OnClick)]
public void OnBtnTestClick(DocReturnEvent e)
{
thisXDocument.UI.Alert("pressed!");
e.ReturnStatus = true;
}

Any ideas?

TIA
Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top