2016-07-12 6 views
-4

asp.netページのcodebehindページから4のJavaスクリプト関数を呼び出す必要があります.3つのjavascript関数でうまく動作しますが、4番目の検証関数が追加されます。検証機能は動作しますが、他の機能は動作しません。私は、ボタンをクリックするとcodebehindから複数のjavascript関数を呼び出す必要があります。それは3つのjavascript関数が正常に動作しますが、それ以上のものはありません

これは機能します!

btnSubmit.OnClientClick = "return Getprodsize('" + hdnprdsize.ClientID + "');return formatSpecifications('" + hdnSpecifications.ClientID + "');return Getselectedvalue('" + hdndrop.ClientID + "')"; 

このdoesntの仕事...

btnSubmit.OnClientClick = "return Validate();Getprodsize('" + hdnprdsize.ClientID + "');return formatSpecifications('" + hdnSpecifications.ClientID + "');return Getselectedvalue('" + hdndrop.ClientID + "')"; 

function Validate() { 
 
    var existing = $("#ctl00_contentMain_lblProductleft").text(); 
 
    if ($('#ctl00_contentMain_txtProductName').val() == '') { 
 
    $('#ctl00_contentMain_txtProductName').focus().css("border-color", "red"); 
 
    return false; 
 
    } 
 
    if ($('#ctl00_contentMain_Txtbrandname').val() == '') { 
 
    $('#ctl00_contentMain_Txtbrandname').focus().css("border-color", "red"); 
 
    return false; 
 
    } 
 
    if ($('#ctl00_contentMain_Txtstock').val() == '') { 
 
    $('#ctl00_contentMain_Txtstock').focus().css("border-color", "red"); 
 
    return false; 
 
    } 
 
    if ($('#ctl00_contentMain_Txtprice').val() == '') { 
 
    $('#ctl00_contentMain_Txtprice').focus().css("border-color", "red"); 
 
    return false; 
 
    } 
 
    if ($('#ctl00_contentMain_txtShortDescription').val() == '') { 
 
    $('#ctl00_contentMain_txtShortDescription').focus().css("border-color", "red"); 
 
    return false; 
 
    } 
 
    if ($('#ctl00_contentMain_txtLongDescription').val() == '') { 
 
    $('#ctl00_contentMain_txtLongDescription').focus().css("border-color", "red"); 
 
    return false; 
 
    } 
 
    if ($('#ctl00_contentMain_ddlbcatgory option:selected').val() == 0) { 
 
    alert("Please Select Catagory"); 
 
    return false; 
 
    } 
 
    if ($('#ctl00_contentMain_txtdeleverycharge').val() == 0) { 
 
    $('#ctl00_contentMain_txtdeleverycharge').focus().css("border-color", "red"); 
 
    return false; 
 
    } 
 
    var txval = $('input[name=optradio]:checked').val(); 
 
    $('#<%=hdnTax.ClientID%>').val(txval); 
 
    return true; 
 
}

答えて

0

あなたはonClientClick属性に複数のreturnステートメントを持つことはできません。最初のものが返され、残りは実行されません。 returnを使用せずに他の関数を呼び出し、Validate()関数の値を返す必要があります。

btnSubmit.OnClientClick = "Getprodsize('" + hdnprdsize.ClientID + "'); formatSpecifications('" + hdnSpecifications.ClientID + "'); Getselectedvalue('" + hdndrop.ClientID + "'); return Validate();"; 

あなたが最初の検証をチェックし、それが失敗した場合に他の関数を呼び出すしないようにしたい場合は、あなたが新しいの外に、このすべてのロジックを移動した場合、あなたがif

btnSubmit.OnClientClick = "if(Validate()) {Getprodsize('" + hdnprdsize.ClientID + "'); formatSpecifications('" + hdnSpecifications.ClientID + "'); Getselectedvalue('" + hdndrop.ClientID + "'); return true;} else return false"; 

を使用することが容易になるだろう関数を呼び出し、その関数をOnClientClickで呼び出しただけです。

function validateAndFormat(sizeID, specID, dropID) { 
    if(Validate()) { 
     Getprodsize(sizeID); 
     formatSpecifications(specID); 
     Getselectedvalue(dropID); 
     return true; 
    } else { 
     return false 
    } 
} 

btnSubmit.OnClientClick = "validateAndFormat('" + hdnprdsize.ClientID + "', '" + hdnSpecifications.ClientID + "' + "', '" + hdndrop.ClientID + "');" 
+0

ありがとうございます。 – Adam

+0

これで問題が解決する場合は、チェックマークをクリックして回答を受け入れる必要があります。 – Barmar

関連する問題