我想知道如何在代码后面访问模态表单元素。我也想知道如何在模态表单上应用jquery验证器。
我的网络表单代码如下
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="HotelReservation.Views.test" %>
<!DOCTYPE html>
<style>
.modal-backdrop {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1030;
background-color: #333333;
opacity:0.5;
}
</style>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script src="../js/jquery-3.3.1.min.js"></script>
<script src="../js/jquery.validate.js"></script>
<script src="../js/jquery.validate.min.js"></script>
<script src="../js/bootstrap.js"></script>
<link href="../css/bootstrap.css" rel="stylesheet" />
<script src="../js/customLoginJS.js"></script>
<link href="../css/StyleSheetLoginPage.css" rel="stylesheet" />
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' />
<title>Login</title>
</head>
<body style="background-image:url('../images/f_img_132.png')" >
<div class="form-container" style="background-color: rgba(179, 179, 179,0.9); width: 23%; margin: auto; margin-top: 170px; padding-bottom: 60px; padding-top: 16px; border-radius: 20px; z-index: 100">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-4"></div>
<form id="form1" runat="server" style="margin-top: 100px;">
<fieldset>
<legend style="font-family: 'Montserrat'">Login</legend>
<div class="form-group row">
<label for="staticEmail" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="text" readonly="" class="form-control-plaintext" value="email@example.com" />
</div>
</div>
<div class="form-group">
<label style="font-family: 'Montserrat'" for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" runat="server" aria-describedby="emailHelp" placeholder="Enter email" />
<small id="emailHelp" class="form-text text-muted-white">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label style="font-family: 'Montserrat'" for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" runat="server" placeholder="Password" />
</div>
<label id="error" runat="server" style="color: red"></label>
<br />
<button id="Button1" type="submit" runat="server" onserverclick="Button1_ServerClick" class="btn btn-outline-primary">Login</button>
<a href="#">Forgot Password?</a>
<br />
<br />
<%--<button type="submit" id="idSignUp" runat="server" class="btn btn-outline-primary">Sign Up</button>--%>
<div class="btn btn-outline-primary" data-toggle="modal" data-target="#mymodal">Sign Up</div>
</fieldset>
<div class="modal" id="mymodal">
<div class="modal-dialog" role="document" >
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" style="font-family: 'Montserrat'">Register</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<input type="text" class="form-control" id="name" placeholder=" Full Name" required="required"/>
</div>
<div class="form-group">
<input type="email" class="form-control" id="uname" placeholder="User Name" required="required"/>
</div>
<div class="form-group">
<input type="password" class="form-control" id="pwd" placeholder="Password" required="required"/>
</div>
<div class="form-group">
<input type="password" class="form-control" id="Password1" placeholder="Confirm Password" required="required"/>
</div>
<div class="form-group">
<input type="text" class="form-control" id="Text1" placeholder="City" required="required"/>
</div>
<div class="form-group">
<input type="text" class="form-control" id="Text2" placeholder="Country" required="required"/>
</div>
<div class="form-group">
<input type="text" class="form-control" id="Text3" placeholder="Zipcode" required="required"/>
</div>
<div class="form-group">
<input type="date" class="form-control" value="Enter birthday" name="bday" required="required"/>
</div>
<br />
</div>
<div class="modal-footer">
<button type="submit" runat="server" class="btn btn-warning" onserverclick="Unnamed_ServerClick">Register</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
我的jquery验证程序的javascript代码是这样的:-
<script>
$(document).ready(function () {
var $validator = $("#form1").validate({
rules: {
uname: {
required: true,
email: true,
minlength: 3
}
}
})
});
</script>
</body>
</html>
我后面的代码是:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace HotelReservation.Views
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_ServerClick(object sender, EventArgs e)
{
string uname = exampleInputEmail1.Value;
}
protected void Unnamed_ServerClick(object sender, EventArgs e)
{
//here i want to access modal elements like the text box etc
}
}
}
在此先谢谢您的帮助。我想要一个jquery验证器和一个用于模式元素的后台代码。
答案 0 :(得分:1)
简单起见,只需使用ajax即可完成操作。使用ajax访问服务器上的数据或在模式控件上设置数据,这将是最简单的