aspxgridview CustomButtonCallback 不支持弹出消息提

作者:郫县华伟包装厂 来源:www.cdhwms.com 发布时间:2017-09-06 09:18:16
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:


[csharp] protected void ASPxGridView1_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomButtonCallbackEventArgs e)
{
throw new Exception("Here I am!");
}

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

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 的时候后台直接抛出错误了,,这个方法也行不通,再找。。。

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

[csharp] 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"] = "此单据已经审核!";
}
}
}

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"] = "此单据已经审核!";
}
}
}[javascript] function EndCallBack(s, e) {
if (s.cpErrorMsg!="") {
alert(s.cpErrorMsg);
}
}

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:孝感网站制作 http://xiaogan.666rj.com

  • 上一篇:一步一步学python(三) - 使用字符串
  • 下一篇:最后一页