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)也無濟(jì)于事,在網(wǎng)上查了很久,官方有個解決辦法,原文如下:
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.
但是實際測試中發(fā)現(xiàn)了問題, throw 的時候后臺直接拋出錯誤了,,這個方法也行不通,再找。。。
最終還是在官網(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"開頭。
測試通過,呵呵
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.
但是實際測試中發(fā)現(xiàn)了問題, throw 的時候后臺直接拋出錯誤了,,這個方法也行不通,再找。。。
最終還是在官網(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"開頭。
測試通過,呵呵
相關(guān)文章
ASP.NET MVC 數(shù)據(jù)驗證及相關(guān)內(nèi)容
這篇文章主要介紹了ASP.NET MVC 數(shù)據(jù)驗證及相關(guān)內(nèi)容的相關(guān)資料,需要的朋友可以參考下2014-10-10ASP.Net中的async+await異步編程的實現(xiàn)
這篇文章主要介紹了ASP.Net中的async+await異步編程的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08ASP.NET Core使用JWT認(rèn)證授權(quán)的方法
這篇文章主要介紹了ASP.NET Core使用JWT認(rèn)證授權(quán)的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11