Advertisement
Guest User

Ext.NET with ASP.NET Validation

a guest
Sep 2nd, 2011
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 1.85 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2.  
  3. <script runat="server">
  4.     protected override void OnLoad(EventArgs e) {
  5.         base.OnLoad(e);
  6.        
  7.         Page.Validate();
  8.  
  9.     }
  10.  
  11.     void ServerValidation(object source, ServerValidateEventArgs args)
  12.     {
  13.         try
  14.         {
  15.             // Test whether the value entered into the text box is even.
  16.             int i = int.Parse(args.Value);
  17.             args.IsValid = ((i % 2) == 0);
  18.         }
  19.         catch (Exception ex)
  20.         {
  21.             args.IsValid = false;
  22.         }
  23.     }
  24.  
  25.     void Button_Click(object sender, EventArgs e) {
  26.         // Display whether the page passed validation.
  27.         if (Page.IsValid) {
  28.             Label1.Text = "Page is valid.";
  29.         } else {
  30.             Label1.Text = "Page is not valid!";
  31.         }
  32.     }
  33.  
  34.  
  35. </script>
  36.  
  37. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  38. <html xmlns="http://www.w3.org/1999/xhtml">
  39. <head id="Head1" runat="server">
  40.     <title>Ext.NET Example</title>
  41. </head>
  42. <body>
  43.     <form id="Form1" runat="server">
  44.     <ext:ResourceManager ID="ResourceManager1" runat="server" />
  45.     <ext:Label ID="Label1" runat="server" Text="Enter an even number:" />
  46.     <br/>
  47.     <ext:TextField ID="TextField1" runat="server" />
  48.     <asp:CustomValidator ID="CustomValidator1"
  49.         runat="server"
  50.         ControlToValidate="TextField1"
  51.         OnServerValidate="ServerValidation"
  52.         ErrorMessage="Not an even number!" />
  53.     <ext:Button ID="Button1" runat="server" Text="Validate" AutoPostBack="false" CausesValidation="true">
  54.         <DirectEvents>
  55.             <Click OnEvent="Button_Click" />
  56.         </DirectEvents>
  57.     </ext:Button>
  58.     <br/>
  59.     </form>
  60. </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement