How to show a message box from edit/add new button click of a devexpress gridview

房东的猫 提交于 2019-12-12 05:43:09

问题


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:


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.



来源:https://stackoverflow.com/questions/9743294/how-to-show-a-message-box-from-edit-add-new-button-click-of-a-devexpress-gridvie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!