我正在处理一个旧项目,我试图对其进行更新并向其中添加一些内容,并且遇到了我要验证的表单问题。
我尝试将RequiredValidator字段添加到所有表单字段中,但是没有用。我注意到该项目正在使用“ SX:VInput”,并且我之前从未见过,所以它让我很沮丧。代码如下:
Checkout.Aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Pages/Store.Master"
AutoEventWireup="true" CodeBehind="Checkout.aspx.cs"
Inherits="SportsStore.Pages.Cart.Checkout" %>
<asp:Content ID="Content1" ContentPlaceHolderID="bodyContent" runat="server">
<div id="content">
<div id="checkoutForm" class="checkout" runat="server">
<h2>Checkout Now</h2>
Please enter your details, and we'll ship your goods right away!
<div id="errors" data-valmsg-summary="true">
<ul>
<li style="display:inline"></li>
</ul>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="BulletList" ShowMessageBox="true"/>
</div>
<h3>Ship to</h3>
<div>
<label for="name">Name:</label>
<SX:VInput Property="Name" ID="Name" runat="server"/>
</div>
<h3>Address</h3>
<div>
<label for="line1">Line 1:</label>
<SX:VInput Property="Line1" runat="server" />
</div>
<div>
<label for="line2">Line 2:</label>
<SX:VInput Property="Line2" runat="server" />
</div>
<div>
<label for="city">City:</label>
<SX:VInput Property="City" runat="server" />
</div>
<div>
<label for="state">State:</label>
<SX:VInput Property="State" runat="server" />
</div>
<div>
<label for="postalcode">Postal Code:</label>
<SX:VInput Property="PostalCode" runat="server" />
</div>
<h3>Account Information</h3>
<div>
<label for="email">Email:</label>
<SX:VInput Property="Email" runat="server" />
</div>
<div>
<label for="password">Password:</label>
<SX:VInput Property="Password" runat="server" />
</div>
<h3>Options</h3>
<input type="checkbox" id="giftwrap" name="giftwrap" value="true" />
Gift wrap these items?
<p class="actionButtons">
<button class="actionButtons" type="submit">Complete Order</button>
</p>
</div>
<div id="checkoutMessage" runat="server">
<h2>Thanks!</h2>
Thanks for placing your order. We'll ship your goods as soon as possible.
</div>
</div>
</asp:Content>
Vinput.cs
namespace SportsStore.Controls
{
public class VInput : WebControl
{
private string nspace = "SportsStore.Models";
private string model = "Order";
public string Namespace
{
get { return nspace; }
set { nspace = value; }
}
public string Model
{
get { return model; }
set { model = value; }
}
public string Property { get; set; }
protected override void RenderContents(HtmlTextWriter output)
{
output.AddAttribute(HtmlTextWriterAttribute.Id, Property.ToLower());
output.AddAttribute(HtmlTextWriterAttribute.Name, Property.ToLower());
Type modelType = Type.GetType(string.Format("{0}.{1}", Namespace, Model));
PropertyInfo propInfo = modelType.GetProperty(Property);
// var attr = propInfo.GetCustomAttribute<RequiredAttribute>(false);
// if (attr != null)
// {
// output.AddAttribute("data-val", "true");
// output.AddAttribute("data-val-required", attr.ErrorMessage);
// }
output.RenderBeginTag("input");
output.RenderEndTag();
}
public override void RenderBeginTag(HtmlTextWriter writer)
{
}
public override void RenderEndTag(HtmlTextWriter writer)
{
}
}
}
在发送到服务器之前,如何获得此表单进行验证?它只是提交而没有立即验证,我需要验证。谢谢。