2016-08-11 31 views
1

私はいくつかのチュートリアル/デモを見たことがありますが、私のASPXページ(C#)の問題を解決することはできません。 私はポップアップに確認メッセージボックスを表示します。&ボタンクリックイベントのボタンがありません。ですが、条件はです。条件が真の確認ボックスである場合は、ボタンをクリックした後、それはのような状態をチェックしますASPXページの条件に確認ボックスをポップアップする方法は?

(> b)の場合は、スキップそうアップpopedされ、何のメッセージがアップpopedません。 その後、確認メッセージボックスで[はい]ボタンをクリックすると、さらに処理が進められます。

「私は初心者です」というコードを入力してください。

+0

あなたが何をしようとしたのですか?それはまっすぐです。 –

+0

あなたは何を使って作業しようとしているかを示すコードはありますか? js関数を指すようにclickイベントのボタンを設定することができます。関数では、条件をチェックし、confirm();を使用します。 – Fredd

+0

私は変数AとBの2つの値を持っています。私は、AがBよりも低く、**挿入コマンド**を実行していることを確認したいと思います。 AがBよりも低くない場合は、メッセージボックスがポップアップされ、その挿入コマンドを実行するための確認を求める必要があります。ユーザーが「はい」をクリックすると、コマンドは実行され、「いいえ」ボタンがクリックされた場合は何も実行されません。 –

答えて

0

これは正しい軌道上にあるはずです。 yesnoconfirm()によって実装されていないあなたは以下sweetalert

var select = document.getElementById('c'), 
 
    btn = document.getElementById('check'); 
 

 
// Add click event 
 
btn.onclick = function(){ 
 

 
    var value = select.options[select.selectedIndex].value; // I could also use Boolean(value); to convert it to boolean and not use quote for comparsion. 
 
    
 
    // Checking if condition is true. If yes, then ask for user confirmation. 
 
    if(value == '1'){ 
 
     
 
     console.log('condition is true; asking for confirmation'); 
 
     
 
     var ask = confirm('The condition is true, do you want to continue?'); 
 
     // if confirmed; 
 
     if(ask){ 
 
     console.log('confirmed'); 
 
     // if denied/cancelled 
 
     } else { 
 
     console.log('cancelled'); 
 
     } 
 
    } 
 

 
}
Condition: 
 
<select id="c"> 
 
    <option value="1">true</option> 
 
    <option value="0">false</option> 
 
</select> 
 
<button id="check">Check</button>

+0

どこにコードを書くべきですか? –

+0

'value == '1''を自分の条件に置き換えてください。私は、あなたが最初にやっていくための最小限の例を提供しました。 <オプション値= "1">真 <オプション値= "0">偽 <ボタンID:私は次のコード の条件を記述するべきタグの下 –

+0

= "check">チェック –

1

などの代替に切り替えてBootstrap.Simpleを使用して初心者のための本当に簡単な例でコピーして、以下のコードを貼り付けそして、それは動作します:背後

コード(.csファイルのファイル):

protected void Page_Load(object sender, EventArgs e) 
{ 
} 

protected void btnClick_Click(object sender, EventArgs e) 
{ 
    lblOutput.Text = String.Empty; 
    bool showModal = true; 

    if(showModal) 
     ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#myModal').modal('show');", true); 
} 

protected void Decision_Command(object sender, CommandEventArgs e) 
{ 
    lblOutput.Text = "User clicked - " + e.CommandArgument; 
} 

.ASPX:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script> 
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <asp:Button ID="btnClick" runat="server" Text="OK" OnClick="btnClick_Click" /> 
     <asp:Label ID="lblOutput" runat="server"></asp:Label> 
     <div id="myModal" class="modal fade"> 
      <div class="modal-dialog"> 
       <div class="modal-content"> 
        <div class="modal-header"> 
         <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
         <h4 class="modal-title" id="myModalLabel">Would you like to continue?</h4> 
        </div> 
        <div class="modal-body"> 
         <h3>Would you like to coninue?</h3> 
         <asp:Button ID="btnYes" runat="server" Text="Yes" OnCommand="Decision_Command" CommandArgument="Yes" /> 
         <asp:Button ID="btnNo" runat="server" Text="No" OnCommand="Decision_Command" CommandArgument="No" /> 
        </div> 
        <div class="modal-footer"> 
         <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button> 
        </div> 
       </div> 
      </div> 
     </div> 
    </form> 
</body> 
</html> 

出力:

Popup confirmation using Bootstrap

+0

最後にありがとうございました...私は何をしたいのですか? 1.私のページは確認後にアクティブにならず、隠したままです。 2. "