我有一个带有范围验证器的表单:
<label class="required" for="price">price</label>
<input runat="server" id="price" name="price" type="text" required="required"/>
<asp:RangeValidator runat="server" ControlToValidate="price" ErrorMessage="Must be between 0 and 15,000" MinimumValue="0" MaximumValue="15000"></asp:RangeValidator>
但它拒绝诸如'22'和'5'之类的值,但接受值'0'和'15,000'。最重要的是,它使我的表单的提交按钮对所有输入都没有响应。为什么范围验证器不起作用?
编辑:这是表单按钮
以及当我有rangevalidator时似乎没有触发的提交函数。如果我删除了rangevalidator,则此代码执行:
protected void btnSubmit_Click(object sender, EventArgs e)
{
formInputs.Visible = false;
emailNotification.Visible = true;
MailMessage mail = new MailMessage();
mail.To.Add(emailField.Value);
mail.From = new MailAddress("no-reply@gmail.com");
mail.IsBodyHtml = true;
mail.Subject = "Your Form has been submitted";
mail.Body += "Location: ";
mail.Body += location.SelectedValue + "<br>";
mail.Body += " address: ";
mail.Body += address.Value + "<br>";
mail.Body += "price: " + price.Value + "<br>";
mail.Body += "Date submitted: " + todaysDate.Value + "<br>";
if (FileUploadControl.HasFile)
{
string filename = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
mail.Attachments.Add(new Attachment(HttpContext.Current.Request.MapPath(filename)));
}
SmtpClient smtp = new SmtpClient(System.Configuration.ConfigurationManager.AppSettings["mailsetting"]);
smtp.Send(mail);
}
答案 0 :(得分:3)
在验证器中输入Type =“Integer”,因为您没有给出类型。它可能将type作为字符串,这就是为什么它没有按预期验证。
您的验证器将被修改为
<asp:RangeValidator runat="server" Type="Integer" ControlToValidate="price" ErrorMessage="Must be between 0 and 15,000" MinimumValue="0" MaximumValue="15000"></asp:RangeValidator>