How to show a message box from edit/add new button

2019-08-24 17:47发布

I have a devexpress nested gridview. Both the master and detail gridviews have link buttons for edit and add new activities. After either inserting new row or updating an existing row, I have to show a message box saying "Your update has been saved successfully". This could be a simple javascript alert box or a message displayed on the page itself. Both the gridviews use objectdatasource. I tried the following codes in the RowUpdated event of both the gridview and the objectdatasource:

System.Web.HttpContext.Current.Response.Write("alert(Your updated has been saved successfully')");

or

ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + Your updated has been saved successfully+ "');", true);

But in either case, no message box is displayed. If I used the same code in the button click event of a button on the page, then it works fine. I event tried to set the text value of a asp:Literal control. It also didn't work. Any help is greatly appreciated.

thanks

1条回答
倾城 Initia
2楼-- · 2019-08-24 18:32

Handle ASPxGridView.RowInserted and ASPxGridView.RowUpdated grid events to set custom property containing message into ASPxGridView.JSProperties.
Then handle client side ASPxClientGridView.EndCallback event to check if custom property exists and raise alert.

protected void ASPxGridView1_RowUpdated(object sender, ASPxDataUpdatedEventArgs e) {
    if (e.Exception == null) {
        ((ASPxGridView)sender).JSProperties["cpUpdatedMessage"] = "Your update has been saved successfully";
    }
}
<dx:aspxgridview ID="ASPxGridView1" ... onrowupdated="ASPxGridView1_RowUpdated">
    <clientsideevents
        EndCallback="function(s, e) {
                        if (s.cpUpdatedMessage) {
                            alert(s.cpUpdatedMessage);
                            delete s.cpUpdatedMessage;
                        }
                    }"
    />

Do the same for RowInserted event. There is similar example in DevEx support center.

Alternatively, you can use solution with e.command parameter.

查看更多
登录 后发表回答