2017-02-22 4 views
0

3つのビューを持つWebページがあり、2つ目のビューで1つのJavaScript関数を検証したいと思います。私はこの関数を追加しない場合、このJavaScript関数を追加している間、必須フィールドの検証がうまく動作しており、ページロード要求フィールドの検証を呼び出そうとしても動作しません。他のJavaScriptを追加中にフィールドの検証が機能しない

function checkDate() 
    {   
     var dt = new Date(); 
     var month =1 + dt.getMonth(); 
     var day = dt.getDate(); 
     var e = document.getElementById("<%=PurchMonth.ClientID%>"); 
     var monthvalue = e.options[e.selectedIndex].value; 
     var e1 = document.getElementById("<%=PurchDay.ClientID%>"); 
     var dayvalue = e1.options[e1.selectedIndex].value; 

     if (monthvalue < month) 
     {     
      return true; 
     } 
     else if (monthvalue ==month) 
     { 
      if (dayvalue>day) 
      { 
       alert("Future Date is not allowed"); 
       return false; 
      } 
      else 
      { 
       return true; 
      } 
     } 
     else     
     { 
      alert("Future Date is not allowed"); 
      return false; 
     } 
    } 

protected void Page_Load(object sender, EventArgs e) 
    { 
     btnModelsNext.Attributes.Add("onclick", "return checkDate();"); 
    } 

答えて

0

function Validate() { 
     if (Page_ClientValidate()) { 
      return checkDate(); 
     } 
     return false; 
    } 

    function checkDate() 
    { rest of the code 
     } 
を以下のように私は、コード

protected void Page_Load(object sender, EventArgs e) 
    { 
     btnModelsNext.Attributes.Add("onclick", "return Validate();"); 
    } 

後に変更されたとJavaScriptは次のようになります

関連する問題