是否有可能在ASPxGridview事件中使用c#代码显示警报?

本文关键字:代码 显示 有可能 ASPxGridview 事件 是否 | 更新日期: 2023-09-27 18:14:09

我写了代码但没有显示警告:

protected void gvRole_RowInserted(objectsender,DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
    if (e.Exception == null)
    {
        //I dont want like this 
        //((ASPxGridView)sender).JSProperties["cpInsertedRole"] = "New Role Inserted";
        //I want Like
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "alert('New Role Inserted ');",true);
    }
}

是否有可能在ASPxGridview事件中使用c#代码显示警报?

您需要检查调用后端客户端脚本处理程序中的JSProperties,并根据该方法中的JSProperties生成警报。

<ClientSideEvents EndCallback="HandleGridCallBackEnd" />
function HandleCallBackEnd(s, e) {
        var grid = ASPxClientControl.GetControlCollection().GetByName("ASPxGridView");
        if (grid != undefined) {
            if (grid.cpInsertedRole!= undefined
                && grid.cpInsertedRole.length > 0) {
                alert(grid.cpInsertedRole);
                grid.cpInsertedRole= '';
            }
        }

如果你想的话,也可以从c#中注册javascript

使用Java脚本,我得到警报,但使用c#不得到

<ClientSideEvents EndCallback="function(s, e) {    
    if(typeof(gvAppUser.cpInsertedRole) != 'undefined')
    {
    alert(gvAppUser.cpInsertedRole);
    delete gvAppUser.cpInsertedRole;
    }
    }" />