2012-05-07 49 views
0

我有一些代碼,看起來像這樣,所有的代碼隱藏...調用JavaScript函數從代碼隱藏和返回值

var script = "confirm('Would you like to close this order?')"; 
ClientScript.RegisterStartupScript(typeof(Page), "CloseOrder", script, true); 

我如何在未來的用戶是否是點擊的價值或沒有線?有可能當這個腳本觸發它會返回值並繼續在代碼隱藏的下一行?

回答

1
var script = function(){ 
    var choice = confirm('Would you like to close this order?'); 
    if(choice){ 
     //If the user clicks yes 
    }else{ 
     //If the user clicks no 
    } 
} 
ClientScript.RegisterStartupScript(typeof(Page), "CloseOrder", script, true); 
+0

由此判斷,我認爲必須在確認後調用WebMethod來關閉訂單服務器端,並且不能直接在我當前的C#CodeBehind方法內關閉它,直接在上面列出的原始行題? –

0

簡單的例子在這裏:http://jsfiddle.net/ChaseWest/W569P/

變化:var script = "confirm('Would you like to close this order?')";

到:var script = confirm('Would you like to close this order?');

此基礎上確認彈出的是或否保存真或假成劇本。

+0

嗨,感謝您的輸入,雖然我不相信您正確理解我的問題,因爲我的帖子。我會編輯它。 –

相關問題