2010-04-20 112 views
0

如果我有一個.aspx頁面,我的表單驗證工作正常,但是如果我有masterpage並且我添加了所有.js和。 css文件在masterpage頭文件中,當我運行然後驗證不起作用,任何想法我如何執行此操作?如何使用ASP.Net WebForm(bassistance.de表單驗證)在MasterPage中實現表單驗證

PS:我使用Bassistance.de表單驗證

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="validation.aspx.cs" Inherits="Web.validation" %> 

<br> 
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<br> 
< html xmlns="http://www.w3.org/1999/xhtml" > <br> 
< head id="Head1" runat="server"><br> 
    <title>Untitled Page</title><br> 
< /head><br> 
< body><br> 
    < form id="form1" runat="server"><br> 
    < div><br> 
    < li><br> 
      < label id="lblFirstName" for="FirstName"><br> 
       First Name : 
      < /label> 
      < input id="FirstName" name="FirstName" type="text" maxlength="25" class="required" /><em><img 
       src="images/required.png" alt="required" /></em> </li> 
      <li><br> 
      < label id="lbllastName" for="LastName"><br> 
       Last Name : 
      < /label><br> 
      < input id="LastName" name="LastName" type="text" maxlength="25" class="required" /><em><img 
       src="images/required.png" alt="required" /></em> </li><br> 
      <li><br> 
      < label id="lblAddr1" for="Addr1"> 
       Address : 
      < /label><br> 
      <input id="Addr1" name="Addr1" type="text" maxlength="25" /> 
      </li> 
      <li> 
      <label id="lblAddr2" for="Addr2"> 
       Address 2 : 
      </label> 
      <input id="Addr2" name="Addr2" type="text" maxlength="25" /> 
      </li> 
      <li> 
      <label id="lblZip" for="txtZip"> 
       Zip : 
      </label> 
      <input id="txtZip" name="txtZip" type="text" class="ZipCodeMask" /> 
      </li> 
      <li> 
      <label id="lblCity" for="City"> 
       City : 
      </label> 
      <input id="City" name="City" type="text" maxlength="25" /> 
      </li> 
      <li> 
      <label id="lblState" for="State"> 
       State : 
      </label> 
      <input id="txtState" name="txtState" type="text" maxlength="25" /> 
      </li> 
      <li> 
      <label id="lblPhone" for="txtPhone"> 
       Phone : 
      </label> 
      <input id="txtPhone" type="text" name="txtPhone" class="phone PhoneMask" /> 
      </li> 
      <li> 
      <label id="lblEmail" for="EMail"> 
       E-Mail : 
      </label> 
      <input id="EMail" name="EMail" type="text" maxlength="100" class="required email" /><em><img 
       src="images/required.png" alt="required" /></em> </li> 
      <li> 
      <label id="lblComment" for="Comment"> 
       Comment or Question : 
      </label> 
      <textarea id="Comment" name="Comment" cols="40" rows="6" class="required"></textarea><em> 
       <img src="images/required.png" alt="required" /></em> </li> 
      <li> 
      <ul> 
       <li> 
       <button id="btnCancel" name="btnCancel" type="button"> 
        Cancel</button></li> 
       <li> 
       <button id="btnReset" name="btnReset" type="reset"> 
        Reset</button></li> 
       <li> 
       <button id="btnSubmit" name="btnSubmit" type="submit"> 
        Submit</button></li> 
      </ul> 
      </li> 


    </div> 
    </form> 
    <script src="js/jquery.validate.min.js" type="text/javascript"></script> 
</body> 
</html> 
+0

我發現這裏的答案是鏈接。 http://www.dotnetcurry.com/ShowArticle.aspx?ID=310 – 2010-04-22 20:15:10

回答

0

這是因爲當你把一個母版頁生成的表單ID。 使用窗體ID「aspnetForm」,它會工作。 例如:

<script type="text/javascript"> 
    $(document).ready(function() { 
     $("#aspnetForm").validate(); 
    }); 
</script> 

,並在HTML它看起來像這樣

<input type="text" id="name" class="required" />