aspxgridview CustomButtonCallback 不支持彈出消息提示解決方法
更新時(shí)間:2013年06月21日 16:23:17 作者:
aspxgridveiw是devexpress的一個(gè)grid控件,使用起來還不錯(cuò),不能再 CustomButtonCallback 事件中使用response.write,具體的解決方法如下,感興趣的朋友可以參考下哈
aspxgridveiw是devexpress的一個(gè)grid控件,使用起來還不錯(cuò)。但是今天遇到一個(gè)問題,就是不能再 CustomButtonCallback 事件中使用response.write,因?yàn)镃ustomButtonCallback 事件是無刷新的,所以不支持,但是即使使用ScriptManager.RegisterClientScriptBlock(page, page.GetType(), "MyScript", myScript, true)也無濟(jì)于事,在網(wǎng)上查了很久,官方有個(gè)解決辦法,原文如下:
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.
但是實(shí)際測(cè)試中發(fā)現(xiàn)了問題, throw 的時(shí)候后臺(tái)直接拋出錯(cuò)誤了,,這個(gè)方法也行不通,再找。。。
最終還是在官網(wǎng)上找到了解決方案,原文地址,我的代碼如下:
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"] = "此單據(jù)已經(jīng)審核!";
}
}
}
function EndCallBack(s, e) {
if (s.cpErrorMsg!="") {
alert(s.cpErrorMsg);
}
}
這里要注意:JSProperties的參數(shù)必須以小寫"cp"開頭。
測(cè)試通過,呵呵
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:
復(fù)制代碼 代碼如下:
protected void ASPxGridView1_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomButtonCallbackEventArgs e)
{
throw new Exception("Here I am!");
}
復(fù)制代碼 代碼如下:
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.
但是實(shí)際測(cè)試中發(fā)現(xiàn)了問題, throw 的時(shí)候后臺(tái)直接拋出錯(cuò)誤了,,這個(gè)方法也行不通,再找。。。
最終還是在官網(wǎng)上找到了解決方案,原文地址,我的代碼如下:
復(fù)制代碼 代碼如下:
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"] = "此單據(jù)已經(jīng)審核!";
}
}
}
復(fù)制代碼 代碼如下:
function EndCallBack(s, e) {
if (s.cpErrorMsg!="") {
alert(s.cpErrorMsg);
}
}
這里要注意:JSProperties的參數(shù)必須以小寫"cp"開頭。
測(cè)試通過,呵呵
相關(guān)文章
ASP.NET MVC 數(shù)據(jù)驗(yàn)證及相關(guān)內(nèi)容
這篇文章主要介紹了ASP.NET MVC 數(shù)據(jù)驗(yàn)證及相關(guān)內(nèi)容的相關(guān)資料,需要的朋友可以參考下2014-10-10MVC使用MvcPager實(shí)現(xiàn)分頁(yè)效果
這篇文章主要為大家詳細(xì)介紹了MVC使用MvcPager實(shí)現(xiàn)分頁(yè)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03ASP.NET中Web API的簡(jiǎn)單實(shí)例
Web API框架是一個(gè)面向Http協(xié)議的通信框架,Web API 框架是一個(gè)面向Http協(xié)議的通信框架。Web API 框架目前支持兩種數(shù)據(jù)格式的序列化:Json 及 Xml。在不做任何配置的情況下,則 Web API 會(huì)自動(dòng)把數(shù)據(jù)使用xml進(jìn)行序列化,否則使用 json 序列化,需要的朋友可以參考下2015-10-10ASP.Net中的async+await異步編程的實(shí)現(xiàn)
這篇文章主要介紹了ASP.Net中的async+await異步編程的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08Mvc動(dòng)態(tài)注冊(cè)HttpModule詳解
本文主要介紹了Mvc動(dòng)態(tài)注冊(cè)HttpModule的方法。具有很好的參考價(jià)值,下面跟著小編一起來看下吧2017-03-03ASP.NET Core使用JWT認(rèn)證授權(quán)的方法
這篇文章主要介紹了ASP.NET Core使用JWT認(rèn)證授權(quán)的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11