Save and Close buttons on EP page

In my development I am mainly using the default buttons in an EP AxForm, gave to us by the framework's properties like: AutoGenerateCancelButton, AutoGenerateInsertButton, AutoGenerateEditButton, and of course these combined with ShowButtonsInActionPane.
Still, sometime you really need to control the behavior of the form, so, the buttons in this case have to be added programmatically by you.

The code snippets that I am using are:

I. in the  .ascx file:

<span runat="server" id="Span_CreditCardButtons" AxCtrlType="AxFormCommandSection" >
    <table class="dynFormControlTable" border="0">
        <tbody>
            <tr class="dynFormControlRow" >
                <td class="dynFormControlCell" colSpan="2" AxType="AxCommandField" >
                    <asp:Button ID="EPSave" runat="server" Text="<%$ axlabel:@SYS12229 %>" OnClick="EPSave_Click" />
                    <asp:Button ID="EPClose" runat="server" Text="<%$ axlabel:@SYS317423 %>" OnClick="EPClose_Click" />
                </td>
            </tr>
        </tbody>
    </table>   
</span> 


II. in the .ascx.cs file:

     protected void EPClose_Click(object sender, EventArgs e)
    {
        this.CloseForm();
    }

    protected void EPSave_Click(object sender, EventArgs e)
    {
        this.WriteEntity();
    }


    private void CloseForm()
    {
        this.AxForm1.DoCancel();
        DialogHelper.Close(CloseDialogBehavior.RefreshDataSource);
    }


    private void WriteEntity()
    {
        Page.Validate();

        if (Page.IsValid)
        {
            switch (this.AxForm1.CurrentMode)
            {
                case (DetailsViewMode.Insert):
                    this.AxForm1.InsertItem(true);
                    this.AxForm1.ChangeMode(DetailsViewMode.Edit);
                    this.CurrentRow.DataSetView.ReReadReferenceDataSources();
                    break;

                case (DetailsViewMode.Edit):
                    this.AxForm1.UpdateItem(true);
                    this.AxForm1.ChangeMode(DetailsViewMode.Edit);
                    this.CurrentRow.DataSetView.ReReadReferenceDataSources();
                    break;

                default:
                    break;
            }
        }
    }

No comments:

Post a Comment