2013-06-21 151 views
1

我做了一個註冊表單,添加了一些驗證,但他們沒有被定位/解僱,我不確定是什麼錯誤,它似乎在Internet Explore上工作正常,但不是在Firefox上:ASP.NET驗證不起作用

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <style type="text/css"> 
     .auto-style1 { 
      width: 100%; 
     } 
     .auto-style2 { 
      width: 143px; 
      text-align: right; 
     } 
     .auto-style3 { 
      width: 280px; 
     } 
     .auto-style4 { 
      font-size: x-large; 
      text-align: left; 
     } 
    </style> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div class="auto-style4"> 

     Registeration</div> 
     <table class="auto-style1"> 
      <tr> 
       <td class="auto-style2">Username:</td> 
       <td class="auto-style3"> 
        <asp:TextBox ID="tbUserName" runat="server" Width="277px" MaxLength="16"></asp:TextBox> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbUserName" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
        <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="tbUserName" ErrorMessage="4 - 16 Characters!" ForeColor="Red" MaximumValue="16" MinimumValue="4" Type="Integer"></asp:RangeValidator> 
       </td> 
      </tr> 
      <tr> 
       <td class="auto-style2">Password:</td> 
       <td class="auto-style3"> 
        <asp:TextBox ID="tbPassword" runat="server" Width="277px" MaxLength="16"></asp:TextBox> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbPassword" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
        <asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="tbPassword" ErrorMessage="4 - 16 Characters!" ForeColor="Red" MaximumValue="16" MinimumValue="4" Type="Integer"></asp:RangeValidator> 
       </td> 
      </tr> 
      <tr> 
       <td class="auto-style2">Confirm Password:</td> 
       <td class="auto-style3"> 
        <asp:TextBox ID="tbConfPassword" runat="server" Width="277px" MaxLength="16"></asp:TextBox> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="tbConfPassword" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
        <asp:RangeValidator ID="RangeValidator3" runat="server" ControlToValidate="tbConfPassword" ErrorMessage="4 - 16 Characters!" ForeColor="Red" MaximumValue="16" MinimumValue="4" Type="Integer"></asp:RangeValidator> 
       </td> 
      </tr> 
      <tr> 
       <td class="auto-style2">Email:</td> 
       <td class="auto-style3"> 
        <asp:TextBox ID="tbEmail" runat="server" Width="277px"></asp:TextBox> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="tbEmail" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
       </td> 
      </tr> 
      <tr> 
       <td class="auto-style2">First Name:</td> 
       <td class="auto-style3"> 
        <asp:TextBox ID="tb1stName" runat="server" Width="277px" MaxLength="16"></asp:TextBox> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="tb1stName" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
        <asp:RangeValidator ID="RangeValidator4" runat="server" ControlToValidate="tb1stName" ErrorMessage="4 - 16 Characters!" ForeColor="Red" MaximumValue="16" MinimumValue="4" Type="Integer"></asp:RangeValidator> 
       </td> 
      </tr> 
      <tr> 
       <td class="auto-style2">Second Name:</td> 
       <td class="auto-style3"> 
        <asp:TextBox ID="tb2ndName" runat="server" Width="277px" MaxLength="16"></asp:TextBox> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="tb2ndName" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
        <asp:RangeValidator ID="RangeValidator5" runat="server" ControlToValidate="tb2ndName" ErrorMessage="4 - 16 Characters!" ForeColor="Red" MaximumValue="16" MinimumValue="4" Type="Integer"></asp:RangeValidator> 
       </td> 
      </tr> 
      <tr> 
       <td class="auto-style2">Age:</td> 
       <td class="auto-style3"> 
        <asp:TextBox ID="tbAge" runat="server" Width="277px"></asp:TextBox> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="tbAge" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
       </td> 
      </tr> 
      <tr> 
       <td class="auto-style2">Gender:</td> 
       <td class="auto-style3"> 
        <asp:DropDownList ID="dlGender" runat="server" Width="277px"> 
         <asp:ListItem Selected="True">Select Gender</asp:ListItem> 
         <asp:ListItem>Male</asp:ListItem> 
         <asp:ListItem>Female</asp:ListItem> 
        </asp:DropDownList> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="dlGender" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
       </td> 
      </tr> 
      <tr> 
       <td class="auto-style2">Secret Question1:</td> 
       <td class="auto-style3"> 
        <asp:DropDownList ID="dl1stQ" runat="server" Height="24px" Width="277px"> 
         <asp:ListItem Selected="True">Select Question</asp:ListItem> 
         <asp:ListItem>What is your Favourite Car Manufacturer?</asp:ListItem> 
         <asp:ListItem>What is your Favourite Food?</asp:ListItem> 
         <asp:ListItem>What is your Favourite Video Game?</asp:ListItem> 
         <asp:ListItem>What is your Favourite Drink?</asp:ListItem> 
         <asp:ListItem>What is your Favourite Brand?</asp:ListItem> 
        </asp:DropDownList> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="dl1stQ" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
       </td> 
      </tr> 
      <tr> 
       <td class="auto-style2">Answer:</td> 
       <td class="auto-style3"> 
        <asp:TextBox ID="tbAnswer" runat="server" Width="277px"></asp:TextBox> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ControlToValidate="tbAnswer" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
       </td> 
      </tr> 
      <tr> 
       <td class="auto-style2">Secret Question2:</td> 
       <td class="auto-style3"> 
        <asp:DropDownList ID="dlQ2" runat="server" Height="16px" Width="277px"> 
         <asp:ListItem Selected="True">Select Question</asp:ListItem> 
         <asp:ListItem>What is your Favourite Sports Team?</asp:ListItem> 
         <asp:ListItem>Who is your Favourite Singer?</asp:ListItem> 
         <asp:ListItem>Who is your Favourite Actor?</asp:ListItem> 
         <asp:ListItem>Who is your Favourite Actress?</asp:ListItem> 
         <asp:ListItem>Who is your favourite Sports Player?</asp:ListItem> 
        </asp:DropDownList> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="dlQ2" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
       </td> 
      </tr> 
      <tr> 
       <td class="auto-style2">Answer:</td> 
       <td class="auto-style3"> 
        <asp:TextBox ID="tbAnswer2" runat="server" Width="277px"></asp:TextBox> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" ControlToValidate="tbAnswer2" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
       </td> 
      </tr> 
      <tr> 
       <td class="auto-style2">Secret Question3:</td> 
       <td class="auto-style3"> 
        <asp:DropDownList ID="dlQ3" runat="server" Width="277px"> 
         <asp:ListItem Selected="True">Select Question</asp:ListItem> 
         <asp:ListItem>What is your mother Maiden Name?</asp:ListItem> 
         <asp:ListItem>Where were you born?</asp:ListItem> 
         <asp:ListItem>What was your first best friends Name?</asp:ListItem> 
         <asp:ListItem>Who was your first kiss?</asp:ListItem> 
        </asp:DropDownList> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" ControlToValidate="dlQ3" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
       </td> 
      </tr> 
      <tr> 
       <td class="auto-style2">Answer:</td> 
       <td class="auto-style3"> 
        <asp:TextBox ID="tbAnswer3" runat="server" Width="277px"></asp:TextBox> 
       </td> 
       <td> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator14" runat="server" ControlToValidate="tbAnswer3" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator> 
       </td> 
      </tr> 
     </table> 
    </form> 
</body> 
</html> 
+0

這是令人難以置信的模糊 – Jonesopolis

+0

任何JavaScript錯誤消息時Firefox中的「不工作」? –

回答

3

您可以嘗試在加載後的代碼中調用Page.Validate();。您還可以將按鈕CausesValidation的屬性設置爲true。默認情況下,頁面在加載之前不會進行驗證。如果原因驗證爲真,則應在單擊按鈕後進行驗證。您也可以通過調用Page.Validate()來手動強制進行驗證。

+1

服務器端驗證是必須的!你不能只依靠客戶端驗證,因爲它很容易繞過。客戶端驗證非常好,因爲它幾乎是立即反饋,但您必須始終驗證服務器收到的數據。 –

4

您可以在您的firebug中檢查控制檯是否存在任何JavaScript錯誤? 你也可以嘗試爲你的驗證器和按鈕設置驗證組。

2

瀏覽器中顯示哪種類型的錯誤消息或Visual Studio Fire的原因?你沒有提到它。

我認爲你的錯誤信息是這樣的

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive). 

好吧,你可以嘗試使用web配置該波紋管部分進行驗證控制。我希望它能解決你的驗證控制問題。

<appSettings> 
    <!-- 
     For Validation Control 
     --> 
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" /> 
    </appSettings> 

如果問題仍然存在,請將此腳本附加到您的ASPX頁面<head>標記後面。

http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js 

「jquery(區分大小寫)」此消息不應再顯示。

0

做出相同的驗證組中的所有文本,並添加按鈕,驗證

ValidationGroup="AAA" 

和代碼添加到您的保存按鈕:

If (Page.IsValid) Then 
    YOURSQL.Insert() 
'or ur code here' 
    End If