One Handler for Dialog Buttons

I would prefer to have one handler for my buttons in a dialog.  It doesn't seem that MouseEventArgs contains any type of reference to the button that was pressed.  Is there an easy way to get a reference within the handler.  I think it just makes for cleaner code to one function per dialog, then having a separate function for each button.

Thanks,
Mike

1 Reply 1 reply marked as answer

IS Indrajith Srinivasan Syncfusion Team July 20, 2020 10:05 AM UTC

Hi Michael, 
 
Greetings from Syncfusion support, 
 
We have validated your reported query. By default, the Dialog buttons are bound with the native button click actions and you can’t get any details related to Buttons. In order to perform with the click with a single function, we suggest you to extend the DialogButton using the Lambada expression. We have also prepared a sample that tries to meet your requirements. 
 
 
@using Syncfusion.Blazor.Popups 
@using Syncfusion.Blazor.Buttons 
 
<SfButton @onclick="@OpenDialog">Open Dialog</SfButton> 
 
<SfDialog Width="250px" ShowCloseIcon="true" IsModal="true" @bind-Visible="@IsVisible"> 
    <DialogTemplates> 
        <Header> Dialog </Header> 
        <Content> This is a Dialog with button and primary button </Content> 
    </DialogTemplates> 
    <DialogButtons> 
        <DialogButton @ref="DialogButton1" Content="OK" IsPrimary="true" @onclick='(e => CloseDialog(e, DialogButton1))' /> 
        <DialogButton @ref="DialogButton2" Content="Cancel" @onclick='(e => CloseDialog(e, DialogButton2))'/> 
    </DialogButtons> 
</SfDialog> 
 
@code { 
    DialogButton DialogButton1; 
    DialogButton DialogButton2; 
    private bool IsVisible { get; set; } = true; 
 
    private void OpenDialog(MouseEventArgs args) 
    { 
        this.IsVisible = true; 
    } 
 
    public void CloseDialog(MouseEventArgs args, DialogButton ButtonProps) 
    { 
        if (ButtonProps.Content == "OK") 
        { 
            System.Diagnostics.Debug.WriteLine("Ok Button clicked"); 
        } else 
        { 
            System.Diagnostics.Debug.WriteLine("Cancel Button clicked"); 
        } 
    } 
} 
 
 
Please let us know if the solution helps, 
 
Regards, 
Indrajith 


Marked as answer
Loader.
Up arrow icon