[CLOSED] My own component (SearchField)

  1. #1

    [CLOSED] My own component (SearchField)

    I'm creating my own control, that I have called "SearchField".
    This control was based on Ext.Net.CompositeField.
    There is a error that I don't know how to solve.
    Here is it:
    Click image for larger version. 

Name:	erro-searchfield.jpg 
Views:	94 
Size:	106.1 KB 
ID:	3312'

    English message:
    Runtime Error in Microsoft JScript: "Can't get the property value 'alignTo': the object is null or not defined"

    Steps to reproduce:
    Click image for larger version. 

Name:	searchfield-reproduce.png 
Views:	57 
Size:	48.3 KB 
ID:	3313

    SearchField Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using Ext.Net;
    
    namespace BaseExample
    {
        public class SearchField : Ext.Net.CompositeField
        {
            #region locais
            private TextField TextEGUID { get { return Items[0] as TextField; } }
            private Ext.Net.Hidden hiddenGUID = null;
            private Ext.Net.Button Button = null;
            private TextField TextField = null;
            #endregion
    
            #region Construtores
            public SearchField()
                : base()
            {
                Initialize();
                Width = 500;
            }
    
            void Initialize()
            {
                WidthCode = 130;
            }
    
            void RemoteValidation_Validation(object sender, RemoteValidationEventArgs e)
            {
                Ext.Net.X.AddScript("alert('remote validation');");
            }
    
            void Click_Event(object sender, Ext.Net.DirectEventArgs e)
            {
    
            }
            #endregion
    
            #region Eventos
            #endregion
    
            #region Overrides
            public override void Clear()
            {
                base.Clear();
                SetValue("", "", "");
            }
    
            public override void SetValue(object value)
            {
                base.SetValue(value);
                SetValue("", value.ToString(), value.ToString());
            }
    
            public override void Focus()
            {
                Focus(false);
            }
    
            public override void Focus(bool selectText)
            {
                Focus(selectText, 100);
            }
    
            public override void Focus(bool selectText, int delay)
            {
                TextEGUID.Focus(selectText, delay);
            }
    
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
    
                #region EGUID
                TextField t = new TextField();
                t.EnableKeyEvents = true;
                t.IsRemoteValidation = true;
                t.RemoteValidation.Validation += new RemoteValidationDirectEvent.RemoteValidationEventHandler(RemoteValidation_Validation);
                t.RemoteValidation.ValidationEvent = "blur";
                t.ID = ClientID + "_EGUID";
                t.Width = WidthCode;
                t.X = 0;
                t.FieldLabel = "";
    
                Items.Add(t);
                #endregion
    
                #region Button
                Button = new Ext.Net.Button();
                Button.DirectEvents.Click.Event += new Ext.Net.ComponentDirectEvent.DirectEventHandler(Click_Event);
                Button.Icon = Icon.Find;
                Button.X = TextEGUID.X + (int)TextEGUID.Width.Value + 5;
                Items.Add(Button);
                #endregion
    
                #region Descrio
                TextField = new TextField();
                TextField.ID = ClientID + "_Description";
                TextField.Disabled = true;
                TextField.Width = new Unit(Width.Value - WidthCode.Value - 35);
    
                if (XDescription > 0)
                    TextField.X = XDescription;
                else
                    TextField.X = Button.X + 28;
                Items.Add(TextField);
                #endregion
    
                #region GUID
                hiddenGUID = new Hidden();
                hiddenGUID.FieldLabel = "";
                hiddenGUID.ID = ClientID + "_GUID";
                Items.Add(hiddenGUID);
                #endregion
    
                //this.Items.Add(p);
            }
    
            public override ConfigItemCollection CustomConfig
            {
                get
                {
                    ConfigItemCollection result = base.CustomConfig;
    
                    #region mtodo clear
                    ConfigItem item = new ConfigItem("clear",
                                string.Format("#({0}.clear();{1}.clear();{2}.clear();)", TextEGUID.ClientID,
                                TextField.ClientID, hiddenGUID.ClientID));
    
                    result.Add(item);
                    #endregion
    
                    #region mtodo setValue
                    item = new ConfigItem("setValue",
                        "function(g,e,d){" +
                                string.Format("{0}.setValue(e);{1}.setValue(d);{2}.setValue(g);",
                                TextEGUID.ClientID, TextField.ClientID, hiddenGUID.ClientID) + "}");
    
                    result.Add(item);
                    #endregion
    
                    return result;
                }
            }
    
            #endregion
    
            #region Propriedades
            public string Description { get; set; }
            public string GUID { get; set; }
            public string EGUID { get; set; }
            public Unit WidthCode { get; set; }
            /// <summary>
            /// posio esquerda do campo descrio
            /// </summary>
            public int XDescription { get; set; }
            #endregion
    
            #region Mtodos Publicos
            public void SetValue(string guid, string eguid, string description)
            {
                GUID = guid;
                EGUID = eguid;
                Description = description;
    
                TextEGUID.SetValue(eguid.ToString());
                TextEGUID.SetValue(eguid.ToString());
                TextField.SetValue(description);
            }
            #endregion
        }
    }
    Design code:
    <%@ Page Language="C#" AutoEventWireup="true" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Register Assembly="BaseExample" Namespace="BaseExample" TagPrefix="example" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server">
        </ext:ResourceManager>
        <form id="form1" runat="server">
        <example:SearchField runat="server" ID="mySf" Width="300" Visible="true" Hidden="false"
            Height="25">
        </example:SearchField>
        </form>
    </body>
    </html>
    []'s
    Last edited by Daniil; Oct 06, 2011 at 8:09 PM. Reason: [CLOSED]
  2. #2
    Try to set ShowBusy=false for RemoteValidation
  3. #3
    Thanks Vladimir.
    Works fine.

    By the way, at line 144 I define a javascript method called setvalue(), how can I execute the server method SetValue(), defined at line 170?

    I know using a directmethod directive. There is another way? Or I have to use directmethods?
  4. #4
    Yes, DirectMethod would be best.

    Please see how to use DirectMethods in a custom control:
    http://forums.ext.net/showthread.php?15060
  5. #5
    Thanks for the tip Daniil.

    PS: please mark as solved :)

Similar Threads

  1. [CLOSED] Image component
    By stoque in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 28, 2011, 10:00 PM
  2. [CLOSED] Calendar Component
    By amitpareek in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Oct 15, 2010, 8:51 PM
  3. [CLOSED] Ext JS 3.3 and PivotGrid component
    By x1000 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 13, 2010, 5:24 AM
  4. Add Ext JavaScript Component to Component
    By geoffrey.mcgill in forum Examples and Extras
    Replies: 3
    Last Post: Mar 10, 2010, 12:38 PM
  5. Replies: 1
    Last Post: May 22, 2009, 7:38 AM

Posting Permissions