如何使用 ASP.Net WebForm 在 MasterPage 中实现表单验证(bassistance.de 表单验证)

发布于 2024-08-29 13:34:02 字数 4226 浏览 1 评论 0原文

如果我有一个 .aspx 页面,我的表单验证工作正常,但如果我有母版页,并且我已在母版页标头中添加了所有 .js 和 .css 文件,当我运行时,验证不起作用,知道我该如何实现那?

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>

if i have a single .aspx page my form validation is working fine but if i have masterpage and i have added all .js and .css file in the masterpage header and when i run then validation does not work, any idea how can i achive that?

PS: i am using Bassistance.de form validation

<%@ 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱*していゐ 2024-09-05 13:34:02

这是因为表单 ID 是在您放入母版页时生成的。
使用表单 id“aspnetForm”就可以了。
示例:

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

在 HTML 中它看起来像这样

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

this is because form id is generated when you put in a master page.
use the form id "aspnetForm" and it will work.
example:

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

and in the HTML it will look like this

<input type="text" id="name" class="required" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文