验证HTML5两个提交按钮.NET [英] Validate HTML5 two submit buttons .NET

查看:97
本文介绍了验证HTML5两个提交按钮.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有表单字段的母版页和一个带有html5验证的asp.net表单字段的页面。两组表单字段都有一个提交按钮。我知道一旦页面编译就会出现在同一个表单上。



我的问题是所有字段都需要验证。我正在使用required =required属性。我不想使用c#中的组验证。



如果选择了一个按钮,我需要提交一个字段,如果另一个按钮,则需要提交其他3个字段按钮被选中。截至目前,如果提交了任一按钮,则必须填写所有表单字段。其中一个表单字段和按钮位于主页中,用于订阅时事通讯,其他字段和按钮位于页面上。



任何帮助都将非常感谢。



谢谢,大法官



我的尝试:



母版页:

I have a master page with a form field and a page with form fields in asp.net using html5 validation. Both sets of form fields have a submit button. I am aware that they are on the same form once the page is compiled.

My problem is that all of the fields require validation. I am using the required="required" attribute. I prefer not to use the group validation from c#.

I need one field to be submitted if one button is selected and the other 3 fields to be submitted if the other button is selected. As of right now, if either button is submitted, ALL form fields must be filled out. One of the form fields and button is in the master page for a newsletter subscription and the other fields and button are on a page.

Any help would be greatly appreciated.

Thanks, Justice

What I have tried:

Master Page:

<div class="input-group">
                        <input runat= "server" name="emailOut" id="emailOut" placeholder="Your Email" class="form-control input-lg font-16" data-height="45px"  />
                        <span class="input-group-btn">
                          <button runat="server" data-height="45px" class="btn btn-colored btn-theme-colored btn-xs m-0 font-14" type="submit" id="submit" name="submit" onServerClick="Submit_Click" formnovalidate="formnovalidate" >Get Started</button>
                        </span>
                      </div>



页码:


Page Code:

<div class="row">
  <div class="col-sm-12">
    <div class="form-group">
      <input runat="server" type="text" placeholder="Enter Name" name="register_name" id="register_name"  class="form-control" />
    </div>
  </div>
  <div class="col-sm-6">
    <div class="form-group">
      <input runat="server" type="text" placeholder="Enter Email" name="register_email" id="register_email" class="form-control"  />
    </div>
  </div>
  <div class="col-sm-6">
    <div class="form-group">
      <input runat="server" type="text" placeholder="Enter Phone" name="register_phone" id="register_phone" class="form-control"  />
    </div>
  </div>
  <div class="col-sm-12">
    <div class="form-group text-center">
      <button runat="server" data-loading-text="Please wait..." class="btn btn-dark btn-theme-colored btn-sm btn-block mt-20 pt-10 pb-10" id="submit2" name="submit2" onServerClick="Submit_Click2">Send Now</button>
    </div>
  </div>
</div>

推荐答案

我要做的是让新闻通讯按钮调用javascript例程来提交值AJAX并有一个单独的函数进程;你也可以把它从页面表单中取出来。



我也有这个AJAX函数例程设置一个cookie,可以在母版页渲染时使用它们不要在后续页面调用中获得相同的表单。
What I would do would be to make the newsletter button a call to a javascript routine to submit the value via AJAX and have a separate function process it; you could also take it out of the page form.

I would also have that AJAX function routine set a cookie that could be used when the master page renders so that they don't get that same form on subsequent page calls.


这篇关于验证HTML5两个提交按钮.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆