aspxgridview CustomButtonCallback 不支持弹出消息提示解决方法
更新时间:2013年06月21日 16:23:17 作者:
aspxgridveiw是devexpress的一个grid控件,使用起来还不错,不能再 CustomButtonCallback 事件中使用response.write,具体的解决方法如下,感兴趣的朋友可以参考下哈
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"开头。
测试通过,呵呵
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"开头。
测试通过,呵呵
相关文章
深入Lumisoft.NET组件开发碰到乱码等问题的解决方法
本篇文章介绍了,在Lumisoft.NET组件开发中碰到乱码等一些问题的解决方法。需要的朋友参考下2013-05-05
Visual Studio实现xml文件使用app.config、web.config等的智能提示
这篇文章主要为大家详细介绍了Visual Studio中xml文件使用app.config、web.config等的智能提示方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2018-09-09
asp.net网站防恶意刷新的Cookies与Session解决方法
这篇文章主要介绍了asp.net网站防恶意刷新的Cookies与Session解决方法,分别以实例的形式讲述了采用cookie法与session法实现WEB页面防止恶意刷新的技巧,需要的朋友可以参考下2014-09-09


最新评论