2012-05-16 28 views
1

我有一個範圍驗證的一種形式:RangeValidator控件拒絕錯誤的值,使我的提交按鈕反應遲鈍

<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」和' 15000' 。最重要的是,它使我的表單的提交按鈕對所有輸入無響應。爲什麼範圍驗證器不工作?

編輯:這裏的表單按鈕

,並且似乎沒有斷火時,我有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("[email protected]"); 
       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); 
}  

回答

3

在驗證程序中給出Type =「Integer」,因爲您沒有給出類型。它可能會將字符串作爲字符串,這就是爲什麼它沒有按預期驗證。

你有驗證器將進行修改,這樣

<asp:RangeValidator runat="server" Type="Integer" ControlToValidate="price" ErrorMessage="Must be between 0 and 15,000" MinimumValue="0" MaximumValue="15000"></asp:RangeValidator> 
+0

這解決了第一個問題,但由於某些原因,它仍然使我的提交按鈕沒有反應。 – jsmith

+0

你可以發佈的代碼是在沒有響應的按鈕的事件 – Adil

+0

我已經將該代碼添加到我原來的問題 – jsmith