EXT.NET 3.0.0 RELEASED!
Now with Tablet Support!
Ext.NET 3.0.0 is here with lots of new cool features and now with tablet support! Check Examples Explorer now to see it in action or download and test it yourself for free!
Results 1 to 4 of 4

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

  1. #1
    Member
    Join Date
    Apr 2010
    Posts
    503

    [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 3:17 PM. Reason: [CLOSED]

  2. #2
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    28,076
    Hello!

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

    Example
    Code:
    <%@ 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.
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  3. #3
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    28,076
    Hello again!

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

    Example
    Code:
    <%@ 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>
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  4. #4
    Member
    Join Date
    Apr 2010
    Posts
    503
    Quote Originally Posted by Daniil View Post
    Hello again!

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

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

Posting Permissions