aspxgridview CustomButtonCallback 不支持弹出消息提示

            aspxgridveiw是devexpress的一个grid控件,使用起来还不错。但是今天遇到一个问题,就是不能再 CustomButtonCallback 事件中使用response.write,因为CustomButtonCallback 事件是无刷新的,所以不支持,但是即使使用ScriptManager.RegisterClientScriptBlock(page, page.GetType(), "MyScript", myScript, true)也无济于事,在网上查了很久,官方有个解决办法,原文如下:(原文地址

 

Hi Troy;

To provide this functionality you should throw an exception in the CustomButtonCallback event handler and process this exception in the CallbackError event handler. Here is the simple sample:

protected void ASPxGridView1_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomButtonCallbackEventArgs e)
    {
        throw new Exception("Here I am!");
    }
if (e.message == 'Here I am!')
 {
   clientErrorImage.SetVisible(true);
 }

If this answer is incomplete or I misunderstood your requirements, please let me know.

Thanks
Kate.

但是实际测试中发现了问题, throw 的时候后台直接抛出错误了,惊讶,这个方法也行不通,再找。。。

最终还是在官网上找到了解决方案,原文地址,我的代码如下:

 protected void ASPxGridView1_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e)
        {
            ASPxGridView view = sender as ASPxGridView;
            if (e.ButtonID == "btnAudit")
            {
                int id = 0;
                int.TryParse(view.GetRowValues(e.VisibleIndex, "id").ToString(), out id);
                if (true)
                    {
                        view.JSProperties["cpErrorMsg"] = "审核成功!";
                        view.DataBind();
                    }
                    else
                    {
                        view.JSProperties["cpErrorMsg"] = "此单据已经审核!";
                    }
            }
        }
 function EndCallBack(s, e) {
        if (s.cpErrorMsg!="") {
            alert(s.cpErrorMsg);
        }
    }


这里要注意:JSProperties的参数必须以小写"cp"开头。

测试通过,呵呵大笑

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BobHe

您的支持就是我的动力,谢谢!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值