validationgroup.aspx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <%@ Page Language="C#" AutoEventWireup="True" %>
  2. <html>
  3. <head>
  4. <script runat="server">
  5. void ButtonClick(Object sender, EventArgs e)
  6. {
  7. if (Page.IsValid)
  8. {
  9. Label.Text="Area is valid.";
  10. }
  11. else
  12. {
  13. Label.Text="Area is not valid!!";
  14. }
  15. }
  16. </script>
  17. </head>
  18. <body>
  19. <form runat="server">
  20. <h3>Area 1</h3>
  21. Enter a number from 1 to 10:
  22. <br>
  23. <asp:TextBox id="TextBox1"
  24. runat="server"/>
  25. <br>
  26. <asp:RangeValidator id="Range1"
  27. ValidationGroup="Area1"
  28. ControlToValidate="TextBox1"
  29. MinimumValue="1"
  30. MaximumValue="10"
  31. Type="Integer"
  32. EnableClientScript="false"
  33. Text="The value must be from 1 to 10!"
  34. runat="server"/>
  35. <br><br>
  36. <asp:Label id="Label1"
  37. runat="server"/>
  38. <br><br>
  39. <asp:Button id="Button1"
  40. ValidationGroup="Area1"
  41. Text="Submit"
  42. OnClick="ButtonClick"
  43. runat="server"/>
  44. <h3>Area 2</h3>
  45. Enter a number from 1 to 10:
  46. <br>
  47. <asp:TextBox id="TextBox1"
  48. runat="server"/>
  49. <br>
  50. <asp:RangeValidator id="Range1"
  51. ValidationGroup="Area2"
  52. ControlToValidate="TextBox1"
  53. MinimumValue="1"
  54. MaximumValue="10"
  55. Type="Integer"
  56. EnableClientScript="false"
  57. Text="The value must be from 1 to 10!"
  58. runat="server"/>
  59. <br><br>
  60. <asp:Label id="Label1"
  61. runat="server"/>
  62. <br><br>
  63. <asp:Button id="Button1"
  64. ValidationGroup="Area2"
  65. Text="Submit"
  66. OnClick="ButtonClick"
  67. runat="server"/>
  68. </form>
  69. </body>
  70. </html>