2016-05-01 11 views
0

asp.netのボタンをクリックすると、クライアントのクリックでそのクリックされたボタンが無効になり、サーバー側のクリックイベントは発生しません。クリック時にボタンが無効になってからクリックボタンが発射されない

<asp:Button ID="ButtonSend2" runat="server" CssClass="CommonButtonStyle" Text="Send Message" OnClientClick="this.disabled='true';return OnClickSendEmail();" 
OnClick="btnSend_Click" ValidationGroup="ValidationGroupCompose" /> 

とこれは私のJavaスクリプトコードです:

私のコードは次のようになり、あなたのjavascriptのコードに

function OnClickSendEmail() { 
    var value = document.getElementById('CE_ctl00_ContentMain_TextArea_ID').getHTML().replace(/&nbsp;/g, "").trim(); 
    if (value == "" || value == undefined) { 
     $j('#ctl00_ContentMain_lblMessage').text('Message body can\'t be blank!'); 
     $j('#ctl00_ContentMain_lblMessage').show()  
     return false; 
    } else { 
     $j('#ctl00_ContentMain_lblMessage').text(''); 
     console.log("Value is returing true"); 
     return true; 
    } 
} 
+0

あなたはUseSubmitBehavior ASPに=「false」にしようとして追加することもできます。ボタン – dmoo

+0

うん、私はこれを使用すると、ボタンが無効になりません –

+0

もこれを試していないし、何のイベントが発生 –

答えて

1

ボタンを無効にすると、ポストバックは行われません。処理の最後にボタンを再度有効にすることもできますが、別の問題があります。ブラウザがビジー状態でOnClickSendEmail()を処理しているときに表示が更新されないため、ボタンが無効に見えることはありません。

function OnClickSendEmail() { 
    var value = document.getElementById('CE_ctl00_ContentMain_TextArea_ID').getHTML().replace(/&nbsp;/g, "").trim(); 
    if (value == "" || value == undefined) { 
     $j('#ctl00_ContentMain_lblMessage').text('Message body can\'t be blank!'); 
     $j('#ctl00_ContentMain_lblMessage').show()  
    } else { 
     $j('#ctl00_ContentMain_lblMessage').text(''); 
     console.log("Value is returing true"); 
     __doPostBack('<%= ButtonSend2.UniqueID %>', ''); 
    } 
} 
:ポストバックは、その後長い処理の終了時に __doPostBackとトリガさ

<asp:Button ID="ButtonSend2" runat="server" OnClientClick="this.disabled = true; setTimeout(OnClickSendEmail, 0); return false;" ... /> 

:ここ

が最初にポストバックをキャンセルし、非同期コマンドを処理することを含む可能性のある解決策であります

0

、最後に発射しませ引き起こす可能性があります2つの点があります。私は可能な点をコードに書いています。また、ValidationGroupComposeバリデーションにそれを含めると、そこから停止していないことは確かですか?

function OnClickSendEmail() { 
    // !!! if the element not found is throw an error here and not continue at all. 
    var value = document.getElementById('CE_ctl00_ContentMain_TextArea_ID').getHTML().replace(/&nbsp;/g, "").trim(); 
    if (value == "" || value == undefined) { 
     $j('#ctl00_ContentMain_lblMessage').text('Message body can\'t be blank!'); 
     $j('#ctl00_ContentMain_lblMessage').show()  
     // !!!! if comes here and return false, then is NOT firing, not continue. 
     return false; 
    } else { 
     $j('#ctl00_ContentMain_lblMessage').text(''); 
     // !!!! if comes here and you not use a browser that support the console, function, is thrown an error and not continue to fire up. 
     console.log("Value is returing true"); 
     return true; 
    } 
} 

デバッグ間違っていただきました、またあなたの最終的なコードからconsole.logを削除見るためにあなたのjavascript。

+0

Sorr yこれはまた働いていない –

関連する問題