偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

ASP.NET數(shù)據(jù)驗證中的驗證組淺析

開發(fā) 后端
ASP.NET數(shù)據(jù)驗證中的驗證組是什么呢?ASP.NET數(shù)據(jù)驗證有什么必要性呢?本文就向你介紹相關信息。

ASP.NET數(shù)據(jù)驗證中的驗證組是什么概念呢?讓我們開始講述:

ASP.NET數(shù)據(jù)驗證是為了防止用戶錄入錯誤數(shù)據(jù)或者漏掉必須填寫的數(shù)據(jù)而使得服務器出現(xiàn)不必要的錯誤,ASP.NET有驗證控件方便我們進行數(shù)據(jù)驗證,但是有時會出現(xiàn)這樣或者那樣的問題,我今天就遇到了一個,把驗證控件說一下吧

  1. ﹤asp:TextBox ID="TextBox1" runat="server"﹥﹤/asp:TextBox﹥  
  2. ﹤asp:RequiredFieldValidator ID="RequiredFieldValidator1" 
  3. ControlToValidate="TextBox1" runat="server" ErrorMessage="RequiredFieldValidator"
  4. ﹤/asp:RequiredFieldValidator﹥  
  5.  ﹤asp:Button ID="Button1" runat="server" Text="Button1" /﹥ 

上面的ASP.NET數(shù)據(jù)驗證代碼實現(xiàn)了最基本的驗證,用戶如果不輸入信息而直接點擊Button1那么ErrorMessage就會顯示出來

  1. ﹤asp:TextBox ID="TextBox1" runat="server"﹥﹤/asp:TextBox﹥  
  2. ﹤asp:RequiredFieldValidator ID="RequiredFieldValidator1"   
  3.  
  4. ControlToValidate="TextBox1" runat="server" ErrorMessage="RequiredFieldValidator"﹥  
  5.  
  6. ﹤/asp:RequiredFieldValidator﹥  
  7. ﹤asp:Button ID="Button1" runat="server" Text="Button1" /﹥  
  8. ﹤asp:Button ID="Button2" runat="server" Text="Button2" /﹥ 

在上面的ASP.NET數(shù)據(jù)驗證代碼中用戶如果不輸入信息而點擊Button1或者Button2那么ErrorMessage都會顯示出來.如果我不想讓Button2引發(fā)驗證怎么辦呢? 好辦,給Button2添加一個屬性 CausesValidation="false" 如下

  1. ﹤asp:TextBox ID="TextBox1" runat="server"﹥﹤/asp:TextBox﹥  
  2. ﹤asp:RequiredFieldValidator ID="RequiredFieldValidator1"   
  3. ControlToValidate="TextBox1" runat="server" ErrorMessage="RequiredFieldValidator"﹥  
  4. ﹤/asp:RequiredFieldValidator﹥  
  5. ﹤asp:Button ID="Button1" runat="server" Text="Button1" /﹥  
  6. ﹤asp:Button ID="Button2" runat="server" Text="Button2"   CausesValidation="false"   /﹥ 

這樣用戶如果在不輸入信息的情況下直接點擊Button2   ErrorMessage就不會出現(xiàn)

但是有時候需要我們在同一頁面驗證不同的信息,你肯定不能將按鈕的 CausesValidation="false" 加上,我們需要加的是ValidationGroup屬性

  1. ﹤asp:TextBox ID="TextBox1" runat="server"﹥﹤/asp:TextBox﹥  
  2. ﹤asp:RequiredFieldValidator ID="RequiredFieldValidator1"   
  3.  
  4. ControlToValidate="TextBox1" ValidationGroup="basicInfo" runat="server" ErrorMessage="error form textbox1"﹥  
  5.  
  6. ﹤/asp:RequiredFieldValidator﹥  
  7. ﹤asp:Button ID="Button1" ValidationGroup="basicInfo" runat="server" Text="Button1" /﹥  
  8. ﹤asp:TextBox ID="TextBox2" runat="server"﹥﹤/asp:TextBox﹥  
  9. ﹤asp:RequiredFieldValidator ID="RequiredFieldValidator2"   
  10.  
  11. ControlToValidate="TextBox2" ValidationGroup="moreInof" runat="server" ErrorMessage="error form textbox2" ﹥  
  12.  
  13. ﹤/asp:RequiredFieldValidator﹥  
  14. ﹤asp:Button ID="Button2" ValidationGroup="moreInof" runat="server" Text="Button2" /﹥ 

這樣就實現(xiàn)了你點擊Button只引發(fā)對特定button的ASP.NET數(shù)據(jù)驗證而不會影響其他的button

總結:使用ASP.NET數(shù)據(jù)驗證驗證組可以將頁面上的驗證控件歸為一組。可以對每個驗證組執(zhí)行驗證,該驗證與同一頁的其他驗證組無關。

將要分組的所有控件的 ValidationGroup 屬性設置為同一個名稱(字符串)即可創(chuàng)建驗證組。可以為驗證組分配任何名稱,但必須對該組的所有成員使用相同的名稱。

ASP.NET數(shù)據(jù)驗證中驗證組的相關信息就向你介紹到這里,希望對你理解ASP.NET數(shù)據(jù)驗證中的驗證組有所幫助。

【編輯推薦】

  1. 哈希算法實現(xiàn)ASP.NET數(shù)據(jù)加密
  2. 對稱加密算法實現(xiàn)ASP.NET數(shù)據(jù)加密
  3. ASP.NET數(shù)據(jù)導入之實現(xiàn)Excel to MSSQL
  4. ASP.NET數(shù)據(jù)集使用示例詳細圖解
  5. ASP.NET數(shù)據(jù)類型轉(zhuǎn)換淺析
責任編輯:仲衡 來源: 百度空間
相關推薦

2009-08-05 16:17:29

ASP.NET For

2009-08-05 16:50:09

ASP.NET For

2009-07-27 17:25:53

ASP.NET驗證控件

2009-08-04 15:20:59

ASP.NET數(shù)據(jù)驗證數(shù)據(jù)驗證控件

2009-08-04 17:41:10

ASP.NET數(shù)據(jù)驗證

2009-08-04 15:36:16

2009-07-29 09:59:10

ASP.NET For

2009-08-05 13:09:17

ASP.NET應用執(zhí)行

2009-08-05 15:29:33

ASP.NET For

2009-09-18 10:20:26

PRG數(shù)據(jù)驗證

2009-08-07 14:40:36

RegularExprASP.NET驗證控件

2009-08-04 16:50:26

2011-04-12 13:53:25

ASP.NET MVCjQuery

2024-05-06 00:00:00

ASP.NET授權機制

2010-06-02 12:32:29

MySQL數(shù)據(jù)庫

2011-05-23 10:37:03

2009-07-29 12:55:44

ASP.NET身份驗證

2009-07-22 14:23:39

URL RewriteASP.NET

2009-07-27 15:34:11

MembershipASP.NET

2009-08-05 18:36:12

ASP.NET Che
點贊
收藏

51CTO技術棧公眾號