title: Asp.net custom control and javascript function
body: <p>There's a custom a asp.net control named PhoneTextBox2. It uses ext.net library, but I doesn't matter.</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PhoneTextBox2.ascx.cs"
      Inherits="Loginet.Web.Controls.PhoneTextBox2" %&gt;
  
   &lt;script type="text/javascript"&gt;
                 var &lt;%=ClientID%&gt;_getNumber = function () {
                  return alert( 'some value');
              }
          &lt;/script&gt;
  &lt;ext:CompositeField runat="server" ID="eCompositeField"&gt;
          &lt;Items&gt;
              &lt;ext:Label ID="PhoneBoxTitle" runat="server" /&gt;
          &lt;/Items&gt;
  &lt;/ext:CompositeField&gt;
  </code></pre>
  
  <p>In aspx page I call the javascript method of <code>PhoneTextBox2</code> by this way</p>
  
  <pre><code>&lt;uc:PhoneTextBox2 runat="server" ID="txtb" /&gt;
  &lt;ext:Button Text="test" runat="server"&gt;
          &lt;Listeners&gt;
              &lt;Click Handler="#{txtb}_getNumber();"&gt;&lt;/Click&gt;
          &lt;/Listeners&gt;
  &lt;/ext:Button&gt;
  </code></pre>
  
  <p><code>#{txtb}_getNumber()</code> is the unique name of the javascript function, and <code>#{txtb}</code> - is the unique name of the <code>PhoneTextBox2</code>.</p>
  
  <p>What can I do to call getNumber by <strong>dot</strong>? </p>
  
  <pre><code>&lt;Click Handler="#{txtb}.getNumber();"&gt;
  </code></pre>
  
  <p>UPDATE:</p>
  
  <pre><code>    public partial class PhoneTextBox2 : System.Web.UI.UserControl {
              /// &lt;summary&gt;
              /// Допускаются ли, чтобы все поля были пустыми
              /// True - Допускаются. Используется тогда, когда данные из этого контрола необязательные.
              /// &lt;/summary&gt;
              public bool EnableEmptyValues { get; set; }
              public string Title { get; set; }
              protected void Page_Load(object sender, EventArgs e) {
  
                  txtCountryCode.AllowBlank = EnableEmptyValues;
                  txtCityCode.AllowBlank = EnableEmptyValues;
                  txtMainPhoneNumber.AllowBlank = EnableEmptyValues;
  
                  if (!IsPostBack &amp;&amp; !Ext.Net.ExtNet.IsAjaxRequest) {
                      PhoneBoxTitle.Text = Title;
                      if (!string.IsNullOrWhiteSpace(DataSource)) {
  
                          string[] phoneNumberArray = DataSource.Split('-');
                          if (phoneNumberArray.Length &gt;= _standartDimension) {
                              txtCountryCode.Text = phoneNumberArray[0];
                              if (txtCountryCode.Text[0] == _plus) {
                                  txtCountryCode.Text = txtCountryCode.Text.Remove(0, 1);
                              }
                              txtCityCode.Text = phoneNumberArray[1];
                              txtMainPhoneNumber.Text = phoneNumberArray[2];
                              if (phoneNumberArray.Length &gt;= _extraDimension) {
                                  txtExtraPhoneNumber.Text = phoneNumberArray[3];
                              }
                          }
                      }
                  }
              }
  
  
              public string DataSource { get; set; }
  
  
              private const string _phoneNumberMask = "+{0}-{1}-{2}-{3}";
              private const char _plus = '+';
              private const int _standartDimension = 3;
              private const int _extraDimension = 4;
  
              public string Number {
                  get {
                      if (!string.IsNullOrWhiteSpace(txtCountryCode.Text) &amp;&amp;
                          !string.IsNullOrWhiteSpace(txtCityCode.Text) &amp;&amp;
                          !string.IsNullOrWhiteSpace(txtMainPhoneNumber.Text)) {
  
                          //Если добавочный номер пустой, то возвратить значения без него
                          if (!string.IsNullOrWhiteSpace(txtExtraPhoneNumber.Text))
                              return string.Format(_phoneNumberMask, txtCountryCode.Text, txtCityCode.Text, txtMainPhoneNumber.Text, txtExtraPhoneNumber.Text);
  
                          string phoneNumber = string.Format(_phoneNumberMask, txtCountryCode.Text, txtCityCode.Text, txtMainPhoneNumber.Text, string.Empty);
                          return phoneNumber.Remove(phoneNumber.Length - 1);
  
                      }
                      return string.Empty;
                  }
              }
  
  
              public bool IsEmpty {
                  get {
                      return (string.IsNullOrWhiteSpace(txtCountryCode.Text) &amp;&amp;
                              string.IsNullOrWhiteSpace(txtCityCode.Text) &amp;&amp;
                              string.IsNullOrWhiteSpace(txtMainPhoneNumber.Text) &amp;&amp;
                              string.IsNullOrWhiteSpace(txtMainPhoneNumber.Text));
                  }
              }
  
  
  
  
              /// &lt;summary&gt;
              /// Validate 
              /// &lt;/summary&gt;
              public void Validate() {
                  if (EnableEmptyValues) {
                      if (!IsEmpty &amp;&amp; Number == string.Empty)
                          MarkInvalid();
                      else
                          MarkValid();
                  }
  
                  else {
                      if (IsEmpty)
                          MarkInvalid();
                      else {
                          if (Number == string.Empty)
                              MarkInvalid();
                          else
                              MarkValid();
                      }
                  }
              }
  
              public void MarkInvalid(string msg = null) {
                  txtCountryCode.MarkInvalid(msg);
                  txtCityCode.MarkInvalid(msg);
                  txtMainPhoneNumber.MarkInvalid(msg);
                  txtExtraPhoneNumber.MarkInvalid(msg);
  
              }
  
              public void MarkValid() {
                  txtCountryCode.MarkAsValid();
                  txtCityCode.MarkAsValid();
                  txtMainPhoneNumber.MarkAsValid();
                  txtExtraPhoneNumber.MarkAsValid();
              }
  
  
               public const string InvalidCheckBoxCssStyle = "border-color:#C30; background:  url('/extjs/resources/images/default/grid/invalid_line-gif/ext.axd') repeat-x scroll center bottom white; width: 40px !important;";
           public const string ValidCheckBoxCssStyle = "border-color:#000; background: none repeat scroll 0 0 transparent;";
  }
  </code></pre>
  
  <p>Note, in <strong>my case</strong> I can't use the server side property <code>Number</code> because of feature of ext.net. Therefore I need to use javascript to get <code>Number</code>.</p>