2013-04-15 74 views
0

我遇到以下情況:用戶點擊asp頁面中的按鈕。由於安全原因,在執行點擊事件期間,系統確定在繼續執行觸發事件之前,有必要應用一些驗證。在modal或radwindow驗證後繼續執行事件

這些驗證顯示在窗口中(在這種情況下是Telerik RadWindow)。在這個RadWindow內部,有一個Web用戶控件(WUC),包含驗證碼或安全代碼,祕密問題等驗證。在用戶寫入驗證碼文本或必要的驗證(它暗示WUC內的回發)之後,WUC應該繼續執行從打開RadWindow的botton中觸發的事件。

我該怎麼做?任何想法?可能嗎?

回答

1

當你打電話給你的RadWindow時,確保設置了OnClientClose事件。如果您是使用代碼隱藏您的RadWindow:

RadWindow newWindow = new RadWindow(); 
newWindow.OnClientClose = "onRadWindowClosed"; 
... 

如果你是通過JavaScript打開你RadWindow,您可以使用add_close()方法:

... 
getRadWindow().add_close('onRadWindowClosed'); 
... 

在這兩種情況下,你需要創建調用頁面上的一個新的事件處理程序腳本的OnClientClose事件:

function onRadWindowClosed(sender, eventArgs) { 
    var returnValue = eventArgs.get_argument(); 

    if (returnValue != null) { 
     if (returnValue == "continue") { 
      // Continue doing work 
     } 
     else { 
      // Throw an error 
     } 
    } 
} 

在您WUC,在btnContinue單擊事件:

protected void btnContinue_Click(object sender, EventArgs e) 
{   
    Page.ClientScript.RegisterClientScriptBlock(GetType(), "closeScript", "getRadWindow().close('continue');", true); 
} 

此功能用於兩個頁面上:

function getRadWindow() { 
    var oWindow = null; 

    if (window.radWindow) 
     oWindow = window.radWindow; 
    else if (window.frameElement.radWindow) 
     oWindow = window.frameElement.radWindow; 

    return oWindow; 
} 

更新到現有的應答

您的呼叫頁面,添加一個函數來獲取RadAjaxManager(假設你已經有了這一頁。如果沒有,你需要一個):

function get_ajaxManager() { 
    return $find("<%= Telerik.Web.UI.RadAjaxManager.GetCurrent(this.Page).ClientID %>"); 
} 

修改您的OnClosed javascript函數(從調用頁面):

function onRadWindowClosed(sender, eventArgs) { 
    var returnValue = eventArgs.get_argument(); 

    if (returnValue != null) { 
     if (returnValue == "continue") { 
      // This call will invoke a server side event 
      get_ajaxManager().ajaxRequest("continue~"); 
     } 
    } 
} 

在您的代碼隱藏,處理服務器端事件得到所謂:

protected void RadAjaxManager1_Request(object source, Telerik.Web.UI.AjaxRequestEventArgs e) 
{ 
    try 
    { 
     if (e.Argument.Trim().Length == 0) 
     { 
      // Show a message when debugging, otherwise return 
      return; 
     } 

     string argument = (e.Argument); 
     String[] stringArray = argument.Split('~'); 

     switch (stringArray[0]) 
     { 
      case "continue": 
       // Continue performing your action or call a specific method 
       ServerSideMethodCall(); 
       break; 
     } 
    } 
    catch (Exception ex) 
    { 
     RadAjaxManager.GetCurrent(this.Page).Alert("Unable to complete operation at this time: " + ex.Message); 
    } 
} 

正如前面提到的,你需要一個RadAjaxManager頁面上,如果你不已經有一個,和你需要的AjaxRequest處理器配合它。

<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" OnAjaxRequest="RadAjaxManager1_Request"></telerik:RadAjaxManager> 

對不起,冗長的回答。讓我知道,如果那得到你所需要的。

+0

這正是我所需要的,我只是遇到了問題,我放在調用WUC的頁面上的WebMethod沒有從onRadWindowClosed javascript函數中被解僱。 – razp26

+0

我已經更新了我的答案,希望能得到您所需的答案。 – McCee

+0

非常感謝! – razp26