Solved

Dialog button command not being called

  • 3 July 2023
  • 7 replies
  • 195 views

Userlevel 4
Badge +2

This should be simple.  I have a custom dialog with some data fields, and an OK button.  I want the OK button to perform a save of the fields as well as other processing.  I’ve tried many things, but so far, my OK button doesn’t perform my associated code.  I defined a new dialog within the page editor.  I added an action button that appears on the menu, and it opens my dialog just fine via button command delegate method and the AskExt() method of the view.  But my OK button just closes the dialog and seemingly does nothing else.  I have tried setting breakpoints after the OK is returned:

if (view.AskExt("viewPanel", true) == WebDialogResult.OK)
{
// other code here, with a breakpoint
}
else
{
// other code here, with a breakpoint
{

and no breakpoints are hit.  I also set the dialog button’s AutoCallback command to a custom method with a breakpoint.  I tried a method signature of both protected void <method>() that matches a button action delegate and a public IEnumerable <method>(PXAdapter), and breakpoint inside these also do not get hit.

I’m assuming there’s something very simple I’m missing, which is unfortunately often the case with such UI behavioral issues, but I’ve tried a combination of many things and no luck yet, so I thought I would run it by the community for some help.

My dialog OK button settings look like this:

 

Does anything obvious jump out?

icon

Best answer by Tony Lanzer 31 July 2023, 03:05

View original

7 replies

Userlevel 4
Badge +1

Have you tried to define a data view that corresponds to the key of your smartpanel and call the AskExt on that data view instead of passing the data view name to AskExt?

It looks like the callback from the panel is not able to hit the proper place.


 

public PXFilter<SOParamFilter> soparamfilter;



this.soparamfilter.AskExt(true);

 

 

Userlevel 4
Badge +2

This is in my aspx.  My PXFormView DataMember is the same as the PXSmartPanel Key.  I tried taking out the panel name in AskExt(), but there was no difference in behavior - the callback method still doesn’t hit the breakpoint.

 

<px:PXSmartPanel runat="server" ID="PanelReadMe" Caption="read.me" CaptionVisible="True" LoadOnDemand="True" AllowResize="True" HideAfterAction="True" AcceptButtonID="btnSave" CancelButtonID="btnCancel" CloseButtonDialogResult="Cancel" Width="1100" Height="575" AutoRepaint="True" AutoReload="True" Key="ReadMeProject" AutoCallBack-Enabled="True" AutoCallBack-Target="frmReadMeDlg" AutoCallBack-Command="ReadMeSave" AutoCallBack-Behavior-CommitChanges="True" AutoCallBack-Behavior-PostData="Page">
<px:PXFormView runat="server" ID="frmReadMeDlg" DataMember="ReadMeProject" Caption="Read.Me" CaptionVisible="False" DataSourceID="ds" NoteIndicator="False" ActivityIndicator="False" Width="1100" Height="550">
<Template>
<px:PXSelector runat="server" ID="CstPXSelector24" DataField="Name" Enabled="False" />
<px:PXTextEdit runat="server" ID="CstPXTextEdit26" DataField="Description" Enabled="False" />
<px:PXRichTextEdit runat="server" DataField="UsrReadMe" ID="edReadMe" Height="600" Width="1100">
<AutoSize Container="Parent" Enabled="True" MinHeight="500" MinWidth="950" />
</px:PXRichTextEdit>
<px:PXLayoutRule runat="server" ID="CstPXLayoutRule8" StartRow="True" />
<px:PXPanel runat="server" ID="PanelButtons" SkinID="Buttons">
<px:PXButton runat="server" ID="PanelButtonsOK" DialogResult="OK" Text="OK" PopupPanel="PanelReadMe">
<AutoCallBack Command="readMeSave" Target="ds" ActiveBehavior="True" Enabled="True">
<Behavior PostData="Page" CommitChanges="True" />
</AutoCallBack>
</px:PXButton>
<px:PXButton runat="server" ID="PanelButtonsCancel" Text="Cancel" DialogResult="Cancel" PopupPanel="PanelReadMe">
<AutoCallBack Command="readMeCancel" Enabled="True" Target="ds" />
</px:PXButton>
</px:PXPanel>
</Template>
<AutoSize Container="Parent" />
</px:PXFormView>
</px:PXSmartPanel>

 

Userlevel 4
Badge +2

Since I posted my aspx, I noticed that the PXSmartPanel AcceptButtonID didn’t match the OK button ID in the popup.  I fixed it, though, and no difference.

Userlevel 5
Badge +1

Hi @Tony Lanzer 

The problem might be due to how you're trying to link the OK button to the method you'd like it to trigger. When using WebDialogResult.OK or WebDialogResult.Yes, the system does not look for a specific method name. It simply checks whether the user has clicked on the button corresponding to that result.

Typically, when you define an action (a button), you have to implement a delegate method that is invoked when the user clicks on the action button. The signature of the method would be like this:

 

public PXAction<YourDAC> YourActionName;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Your Action Name")]
protected virtual IEnumerable yourActionName(PXAdapter adapter)
{
// Your code goes here
return adapter.Get();
}

 

In the case of an OK button in a SmartPanel, you can handle the callback using the RowUpdating event for the DAC that's bound to your panel.

Here's an example:

 

protected void YourDAC_RowUpdating(PXCache sender, PXRowUpdatingEventArgs e)
{
YourDAC dac = (YourDAC)e.NewRow;

// Your save operation and other processing goes here
// Use 'dac' object to access fields values

// Finally, if you want to persist changes immediately:
// sender.PersistUpdated(dac);
}

 

This method will be invoked when OK button is clicked, and you can handle your processing inside it.

Make sure that your PXFormView and PXSmartPanel have the same key defined (which seems to be correct in your case), and the CommitChanges property is set to true for the OK button (which you also have done). The main issue might have been the placement of the method handling the callback for the OK button press.

Try to handle it in the RowUpdating event and it should work for you.

Userlevel 4
Badge +2

Just wanted to circle back and let those who might be interested know how I resolved this…  I ended up starting over a bit and creating a new dialog.  And instead of calling view.AskExt() at all in my toolbar button callback method to popup a dialog, I set the button’s PopupPanel UI property to the dialog’s ID.  After doing this, the dialog still pops open as needed, and the dialog button’s callback command then actually called my method as expected.  Unfortunately, I don’t know why I couldn’t get the initial way to work, but I got it working anyway.

Userlevel 7
Badge

Thank you for sharing your solution with the community @Tony Lanzer!

Only this much is required (Text from your post):-

<px:PXButton runat="server" ID="PanelButtonsCancel" Text="Cancel" DialogResult="Cancel" >
    <AutoCallBack Command="readMeCancel" Enabled="True" Target="ds" />
</px:PXButton>

public PXAction<YourDAC> readMeCancel;
[PXButton(ClosePopup = true)]
protected virtual IEnumerable ReadMeCancel(PXAdapter adapter)
{
    PXTrace.WriteInformation("CancelPressed");
    return adapter.Get();
}
OR
private void ReadMeCancel()
{
    PXTrace.WriteInformation("CancelPressed");
}
And call to show popup from anywhere, View.AskExt();

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved