温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

aspxgridview中CustomButtonCallback不支持弹出消息提示怎么办

发布时间:2021-10-12 14:18:16 来源:亿速云 阅读:89 作者:小新 栏目:开发技术

这篇文章将为大家详细讲解有关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"开头。

关于“aspxgridview中CustomButtonCallback不支持弹出消息提示怎么办”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI