aspxgridview CustomButtonCallback 不支持弹出消息提示解决方法
程序员文章站
2024-02-29 18:06:04
aspxgridveiw是devexpress的一个grid控件,使用起来还不错。但是今天遇到一个问题,就是不能再 custombuttoncallback 事件中使用re...
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"开头。
测试通过,呵呵