.net - .NET webforms 的 HTML5 需要 =""属性

标签 .net html webforms

我正在尝试使用新的 required我的 .NET 4.5 webforms 应用程序中表单字段的属性。

但是,由于只有一个 <form>围绕页面上的所有控件(webforms 样式),浏览器不知道在按下提交按钮时要验证哪些字段。

下面附有具有登录功能和页面搜索功能的精简版页面。

当我点击“搜索”按钮时,我的浏览器告诉我必须先填写用户名和密码字段。当我尝试登录时,它告诉我必须在搜索字段中输入一些文本。因为所有字段都是相同 <form> 的子字段标签。

有其他人遇到过这个问题或提出了解决方案吗?我想使用 HTML5 属性进行表单验证,没有 javascript 解决方案。

<!DOCTYPE html>

<html>
<head>
    <title>Title</title>
</head>
<body>
  <form method="post" runat="server" id="mainform">


    <%// Search %>
    <asp:Panel runat="server" DefaultButton="searchButton" >

      <asp:TextBox runat="server" ID="searchQuery" ClientIDMode="Static" required="required" />
      <asp:Button runat="server" ID="searchButton" ClientIDMode="Static" Text="Search"/>

    </asp:Panel>


    <%// Login %>
    <asp:Panel runat="server" DefaultButton="signInButton">

      <label for="inputusername">Username</label>
      <asp:TextBox runat="server" ClientIDMode="Static" ID="inputusername" required="required" />

      <label for="inputpassword">Password</label>
      <asp:TextBox runat="server" TextMode="Password" ClientIDMode="Static" ID="inputpassword" required="required" />

      <asp:Button ID="signInButton" runat="server" />

    </asp:Panel>

  </form>
</body>
</html>

</html>

最佳答案

请试试这个..它对我有用..

<asp:TextBox runat="server" 
             ClientIDMode="Static" 
             ID="inputusername"                    
             required />

关于.net - .NET webforms 的 HTML5 需要 =""属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15434535/

相关文章:

javascript - TinyMCE 文本区域不响应 'onkeydown' 事件

html - Angular index和app.component.html应该怎么写?

asp.net-mvc - 传统 ASP .NET Web 窗体与 MVC

c# - 如何在我的 C# Visual Studio 项目中添加 VC++ DLL 作为引用?

java - 解析 C# 中以 JSON 发送的 DateTime 类型

mysql - 查询返回 "The method or operation is not implemented."错误

c# - 从后面的代码创建 SqlDataSource 过滤器参数

c# - 如何将resx资源文件变成字典

html - bootstrap,如何将文本放在 div 中的图像上

javascript - 单击一次目标复选框后检查 ="Checked"不工作