Ext.getCmp() by ClientID problem

  1. #1

    Ext.getCmp() by ClientID problem

    I have a JS function to get a ext component by it ClientID but fail.

    First set the Client ID in the code behind:
                txtNoTo.Listeners.BeforeRender.Handler = "this.txtFrId='" + txtNoFr.ClientID + "'";
    Then in JS:

        var txtFr = Ext.getCmp(sender.txtFrId);
    The problem is the txtNoFr.ClientID = "App.tbrDocNo_txtNoTo"
    But by inserting break point in JS, it will be run right if txtNoFr.ClientID = "tbrDocNo_txtNoTo"

    Why the ClientID have a prefix of "App." what is it stand for?

    I also try to clientIDMode to AutoID in Web.config, but get the same result.

        <pages controlRenderingCompatibilityVersion="3.5" clientIDMode ="AutoID">
          <controls>
            <add assembly="Ext.Net" namespace="Ext.Net" tagPrefix="ext"/>
          </controls>
        </pages>
    Can anyone help? Thanks.
  2. #2
    Hello,

    You should not require the call to Ext.getCmp(). Just use the client-side id value.

    Example

    var txtFr = sender.txtFrId;
    Hope this helps.
    Geoffrey McGill
    Founder
  3. #3
    Quote Originally Posted by geoffrey.mcgill View Post
    Hello,

    You should not require the call to Ext.getCmp(). Just use the client-side id value.

    Example

    var txtFr = sender.txtFrId;
    Hope this helps.
    Thanks for your reply.

    But I need to get value of txtNoFr.

    If I use
    var txtFr = sender.txtFrId;
    It seems that txtFr is just a string, but not a ext component.

    I enclose the full code for your reference.

    Code behind
                txtNoFr.Listeners.BeforeRender.Handler = "this.txtToId='" + txtNoTo.ClientID + "'";
                txtNoTo.Listeners.BeforeRender.Handler = "this.txtFrId='" + txtNoFr.ClientID + "'";
                txtNoFr.Validator.Fn = "txtFr_Validating";
                txtNoTo.Validator.Fn = "txtTo_Validating";
                txtNoFr.MaxLength = MaxLength;
                txtNoTo.MaxLength = MaxLength;
    JS
    var txtTo_Validating = function(value) {
        var sender = this;
    
        var q = sender.getRawValue();
        if (!sender.allowBlank) {
            if (q == '') {
                return false;
            }
        }
        if (q.length > sender.maxLength)
            return false;
        var txtFr = Ext.getCmp(sender.txtFrId);
    
        var f = txtFr.getValue().trim();
        var f = txtFr.getValue();
        if (f != '')
            if (f > q)
            return false;
    
        return true;
    }
  4. #4
    Quote Originally Posted by Vinci View Post
    It seems that txtFr is just a string, but not a ext component.
    I believe this is because you are passing the value as a string and not an object.

    Remove the extra set of single quotes, then the value will not be treated as a string.

    Example

    "this.txtFrId=" + txtNoFr.ClientID;
    Hope this helps.
    Geoffrey McGill
    Founder
  5. #5
    Quote Originally Posted by geoffrey.mcgill View Post
    I believe this is because you are passing the value as a string and not an object.

    Remove the extra set of single quotes, then the value will not be treated as a string.

    Example

    "this.txtFrId=" + txtNoFr.ClientID;
    Hope this helps.
    Success after remove the single quote. Many thanks for your help!

Similar Threads

  1. X.GetCmp and FileUploadField
    By josecano in forum 1.x Help
    Replies: 2
    Last Post: May 01, 2013, 7:56 AM
  2. Ext.getCmp() not working in UserControl
    By ontiv in forum 2.x Help
    Replies: 10
    Last Post: Oct 16, 2012, 7:54 AM
  3. [CLOSED] Ext.getCmp return undefined is not an object
    By farisqadadeh in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Aug 27, 2012, 11:50 PM
  4. [CLOSED] Ext.Net.X.GetCmp - how to call in parent?
    By wagger in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 25, 2011, 4:55 AM
  5. [CLOSED] Finding a menu with Ext.getCmp()
    By randy85253 in forum 1.x Legacy Premium Help
    Replies: 10
    Last Post: Jun 22, 2009, 3:40 AM

Posting Permissions