[CLOSED] [1.0] Equivalent to ASP.NET custom validator

  1. #1

    [CLOSED] [1.0] Equivalent to ASP.NET custom validator

    What is the Ext.NET equivalent of an ASP.NET custom validator? I need to call a server side method for validation. Can I get an example of doing this?
    Last edited by Daniil; Aug 24, 2010 at 2:17 PM. Reason: [CLOSED]
  2. #2
    Hello!

    There is no own custom server validation mechanism in the Ext.Net. But you could use <asp:CustomValidator>.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
    
        void Button_Click(object sender, EventArgs e)
        {
            // Display whether the page passed validation.
            if (Page.IsValid)
            {
                Label1.Text = "Page is valid.";
            }
            else
            {
                Label1.Text = "Page is not valid!";
            }
        }
    
        void ServerValidation(object source, ServerValidateEventArgs args)
        {
            try
            {
                // Test whether the value entered into the text box is even.
                int i = int.Parse(args.Value);
                args.IsValid = ((i % 2) == 0);
            }
            catch (Exception ex)
            {
                args.IsValid = false;
            }
        }
    
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Label ID="Label1" runat="server" Text="Enter an even number:" />
        <br/>
        <ext:TextField ID="TextField1" runat="server" />
        <asp:CustomValidator 
            runat="server" 
            ControlToValidate="TextField1"
            OnServerValidate="ServerValidation"
            ErrorMessage="Not an even number!" />
        <ext:Button runat="server" Text="Validate" AutoPostBack="true">
            <DirectEvents>
                <Click OnEvent="Button_Click" />
            </DirectEvents>
        </ext:Button>
        <br/>
        </form>
    </body>
    </html>
    Also don't forget there is very flexible mechanism of client side validation in the Ext.Net. If your scenario allows to store data for validation within a page (as Hidden fields) you could use that. If it needs to do some actions on a server you could use DirectMethods from JavaScript validation function.
  3. #3
    Hello again!

    Also you could use RemoteValidation. Please look at the example.

    Example
    <%@ Page Language="C#" %>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
        
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Remote Validation - Ext.NET Examples</title>
        
        <style type="text/css">
            .validation-indicator{
                background-image: url(/extjs/resources/images/default/grid/loading-gif/ext.axd) !important; 
            }
        </style>
        
        <script runat="server">
            protected void CheckField(object sender, RemoteValidationEventArgs e)
            {
                TextField field = (TextField)sender;
                if (field.Text == "Valid")
                {
                    e.Success = true;
                }
                else
                {
                    e.Success = false;
                    e.ErrorMessage = "'Valid' is valid value only";
                }
    
                System.Threading.Thread.Sleep(3000);          
            }
        </script>
    </head>
    <body>
        <form runat="server">
           <ext:ResourceManager runat="server" />
           
           <ext:FormPanel runat="server" 
                Title="Remote Validation Form" 
                Padding="5"
                Frame="true"
                LabelWidth="250"
                MonitorValid="true"
                Width="500" 
                DefaultAnchor="-20"
                Height="200">
                <Items>
                    <ext:TextField runat="server" FieldLabel="No validation" />
                    <ext:TextField runat="server" FieldLabel="Client only validation" AllowBlank="false" />
                    <ext:TextField runat="server" FieldLabel="Server only validation" IsRemoteValidation="true">
                        <RemoteValidation 
                            OnValidation="CheckField" 
                            Before="this.setIndicatorIconCls('validation-indicator');this.setIndicatorTip('Validating...');" 
                            Complete="this.clearIndicator()" />                    
                    </ext:TextField>
                    <ext:TextField 
                        runat="server" 
                        FieldLabel="Client and server validation" 
                        IsRemoteValidation="true" 
                        AllowBlank="false">
                        <RemoteValidation 
                            OnValidation="CheckField" 
                            Before="this.setIndicatorIconCls('validation-indicator');this.setIndicatorTip('Validating...');" 
                            Complete="this.clearIndicator()" />                    
                    </ext:TextField>
                </Items>
                <Buttons>
                    <ext:Button runat="server" Text="Submit" FormBind="true" />
                </Buttons>
           </ext:FormPanel>
        </form>    
    </body>
    </html>
  4. #4
    Quote Originally Posted by Daniil View Post
    Hello again!

    Also you could use RemoteValidation. Please look at the example.

    Example
    <%@ Page Language="C#" %>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
        
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Remote Validation - Ext.NET Examples</title>
        
        <style type="text/css">
            .validation-indicator{
                background-image: url(/extjs/resources/images/default/grid/loading-gif/ext.axd) !important; 
            }
        </style>
        
        <script runat="server">
            protected void CheckField(object sender, RemoteValidationEventArgs e)
            {
                TextField field = (TextField)sender;
                if (field.Text == "Valid")
                {
                    e.Success = true;
                }
                else
                {
                    e.Success = false;
                    e.ErrorMessage = "'Valid' is valid value only";
                }
    
                System.Threading.Thread.Sleep(3000);          
            }
        </script>
    </head>
    <body>
        <form runat="server">
           <ext:ResourceManager runat="server" />
           
           <ext:FormPanel runat="server" 
                Title="Remote Validation Form" 
                Padding="5"
                Frame="true"
                LabelWidth="250"
                MonitorValid="true"
                Width="500" 
                DefaultAnchor="-20"
                Height="200">
                <Items>
                    <ext:TextField runat="server" FieldLabel="No validation" />
                    <ext:TextField runat="server" FieldLabel="Client only validation" AllowBlank="false" />
                    <ext:TextField runat="server" FieldLabel="Server only validation" IsRemoteValidation="true">
                        <RemoteValidation 
                            OnValidation="CheckField" 
                            Before="this.setIndicatorIconCls('validation-indicator');this.setIndicatorTip('Validating...');" 
                            Complete="this.clearIndicator()" />                    
                    </ext:TextField>
                    <ext:TextField 
                        runat="server" 
                        FieldLabel="Client and server validation" 
                        IsRemoteValidation="true" 
                        AllowBlank="false">
                        <RemoteValidation 
                            OnValidation="CheckField" 
                            Before="this.setIndicatorIconCls('validation-indicator');this.setIndicatorTip('Validating...');" 
                            Complete="this.clearIndicator()" />                    
                    </ext:TextField>
                </Items>
                <Buttons>
                    <ext:Button runat="server" Text="Submit" FormBind="true" />
                </Buttons>
           </ext:FormPanel>
        </form>    
    </body>
    </html>
    Cool. This seems like exactly what I'm looking for. Thanks!

Similar Threads

  1. [CLOSED] Ext.NET equivalent of this sample
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 20
    Last Post: Dec 09, 2011, 6:44 AM
  2. [CLOSED] 'div' equivalent in ext.net?
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 06, 2011, 6:03 PM
  3. [CLOSED] Is there an ext.net equivalent to asp:BulletedList?
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Sep 22, 2010, 8:35 PM
  4. [CLOSED] Custom validator for TextArea
    By shahidmughal in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 04, 2010, 7:05 PM
  5. [CLOSED] Equivalent of Ext.ID via C# Codebehind
    By Steve in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 03, 2009, 3:53 PM

Posting Permissions