简体   繁体   English

如何在Ext.net中使用JavaScript在UserControl中获取控件的元素ID

[英]How to get the Element Id of Control in UserControl using JavaScript in Ext.net

Hai, 海,

I am Writing Age calculation based on DateField value using JavaScript function and trying to fill the value in another Numeric textBox. 我正在使用JavaScript函数基于DateField值编写Age计算,并尝试在另一个Numeric textBox中填充该值。 using the following code. 使用以下代码。

<script>

        function getAge(event, toolEl, panel, tc) {
            debugger;
            var today = new Date();
            var birthDate = new Date(event.getValue());
            var age = today.getFullYear() - birthDate.getFullYear();
            var m = today.getMonth() - birthDate.getMonth();
            if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
                age--;
            }
            if (event.name == 'dtMotherDOB') {
                Ext.getCmp('txtMotherAge').setValue(age);
            }
            else
                Ext.getCmp('txtFatherAge').setValue(age);
            return age;
        }


    </script>


 <ext:DateField ID="dtFatherDOB" runat="server"  FieldLabel="Father DOB"  
                                        Vtype="daterange" EndDateField="dtDOB" EnableKeyEvents="true">
         <Listeners>
                 <Select Fn="getAge"/>
        </Listeners>
  </ext:DateField>

  <ext:NumberField ID="txtFatherAge" runat="server" FieldLabel="Father Age"                       Width="300"  MinValue="20">

    </ext:NumberField>

In above code after selecting the DataField value the i am filling the txtMotherAge value in textBox . 在选择后上面的代码DataField值的我正在填充txtMotherAge中值textBox

using the above code. 使用上面的代码。 Ext.getCmp('txtFatherAge').setValue(age); is used to get the element from form and setting the value of age in textbox . 用于从表单中获取元素并在textbox设置age的值。

The above code is working fine for the simple form. 上面的代码适用于简单的表单。

but when i use this code in UserControl and consume the usercontrol in anotherform. 但是当我在UserControl中使用此代码并在另一个窗体中使用usercontrol时。 Ext.getCmp('txtFatherAge').setValue(age) showing error and Ext.getCmp('txtFatherAge') value becomes 'undefined' . Ext.getCmp('txtFatherAge').setValue(age)显示错误, Ext.getCmp('txtFatherAge')值变为'undefined'

what is the problem in the above code. 上面的代码有什么问题。 how to get the element in usercontrol in ext.net control. 如何在ext.net控件中获取usercontrol中的元素。

Please help me in this regard. 请帮助我这方面。

Thank you. 谢谢。

Try this: 尝试这个:

Ext.getCmp('<%=UserControl1.ClientID%>' + '_' + 'txtFatherAge').setValue(age)

Or, 要么,

Set ClientIDMode="Static" 设置ClientIDMode="Static"

<ext:NumberField ID="txtFatherAge" ClientIDMode="Static" runat="server"    
 FieldLabel="Father Age" Width="300"  MinValue="20"></ext:NumberField>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM