2013-10-01 48 views
-1

我有以下功能:腳本消息框在asp.net

Public Function javaMsg(ByVal message As String) As String 

    Dim sb As New System.Text.StringBuilder() 
    sb.Append("window.onload=function(){") 
    sb.Append("alert('") 
    sb.Append(message) 
    sb.Append("')};") 

    Return sb.ToString() 

End Function 

這就是我如何調用我的函數:

Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", x.javaMsg("Do you want to choose a date?"), True) 

此警報只顯示一個OK按鈕我怎樣才能添加取消按鈕?以及如何使用點擊每個按鈕來完成某項工作?

請注意,我用asp.net與vb.net

+1

使用確認框。 –

+0

@SainPradeep okey now如何在用戶選擇ok時編寫函數,如果用戶選擇取消,我該如何編寫另一個函數? – User7291

+0

@SainPradeep我的意思是來自當然代碼 – User7291

回答

0

,我建議你使用jQuery UI的對話框。這是目前最常用的對話框。

查看以下鏈接:

Dialog

這裏有一個例子:到位警告框

<!doctype html> 

<html lang="en"> 
<head> 
    <meta charset="utf-8" /> 
    <title>jQuery UI Dialog - Modal confirmation</title> 
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
    <link rel="stylesheet" href="/resources/demos/style.css" /> 
    <script> 
    $(function() { 
    $("#dialog-confirm").dialog({ 
     resizable: false, 
     height:140, 
     modal: true, 
     buttons: { 
     "Delete all items": function() { 
      $(this).dialog("close"); 
     }, 
     Cancel: function() { 
      $(this).dialog("close"); 
     } 
     } 
    }); 
    }); 
    </script> 
</head> 
<body> 

<div id="dialog-confirm" title="Empty the recycle bin?"> 
    <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p> 
</div> 

<p>Sed vel diam id libero <a href="http://example.com">rutrum convallis</a>. Donec aliquet leo vel magna. Phasellus rhoncus faucibus ante. Etiam bibendum, enim faucibus aliquet rhoncus, arcu felis ultricies neque, sit amet auctor elit eros a lectus.</p> 


</body> 
</html> 
0

使用confirm代替alert ...

Public Function javaMsg(ByVal message As String) As String 

    Dim sb As New System.Text.StringBuilder() 
     sb.Append("window.onload=function(){"); 
     sb.Append("var r=confirm('"); 
     sb.Append(message); 
     sb.Append("');"); 
     sb.Append("if(r==true){"); 
     sb.Append("alert('clicked OK');}"); 
     sb.Append("else{"); 
     sb.Append("alert('clicked CANCEL');}"); 
     sb.Append("};"); 

     return sb.ToString(); 

End Function 
+0

okey現在如何我可以寫一個函數,如果用戶選擇好了,並且另一個功能,如果用戶選擇取消? – User7291

+0

檢查已編輯的答案 –

+0

我需要在vb後面的代碼中得到確認框的結果..不是javascript .. – User7291