title: ModalPopupExtender, its ID and its BehaviorID return a null when called by javascript
body: <p>I've initialized my MPE as follows:</p>
  
  
  
  <pre><code>&lt;asp:modalpopupextender ID                  ="ModalPopupExtender1"
                      BehaviorID          ="ModalBehavior"
                      runat               ="server"
                      OkControlID         ="btnCancel"
                      CancelControlID     ="btnCancel"
                      TargetControlID     ="dead"
                      PopupControlID      ="Panel1"
                      BackgroundCssClass  ="ModalPopupBG"/&gt;
  </code></pre>
  
  <p>The <code>ModalPopupExtender</code>'s <code>TargetControlID</code> is:</p>
  
  
  
  <pre><code>&lt;asp:Button id="dead" runat="server"/&gt;
  </code></pre>
  
  <p>I then assign my gridview row the onclick attribute to call <code>mpe.Show</code>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>switch (e.Row.RowType)
  {
      case DataControlRowType.DataRow:
          e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand'");
          e.Row.Attributes.Add("onclick", "ShowPopup()");
          break;
  </code></pre>
  
  <p>My <code>ShowPopup()</code> function <em>within the MasterPage</em>:</p>
  
  <pre class="lang-js prettyprint-override"><code>function ShowPopup() {
      var mpe = $find('ModalBehavior');
      mpe.show()
  }
  </code></pre>
  
  <p>I've tried many things to try and produce anything other than a null value when the GridView row is clicked, but they have not worked either. Such as:</p>
  
  <pre class="lang-cs prettyprint-override"><code>switch (e.Row.RowType)
  {
      case DataControlRowType.DataRow:
          e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand'");
          e.Row.Attributes.Add("onclick", String.Format("javascript:$find('{0}').show();", ModalPopupExtender1.ClientID));
          break;
  </code></pre>
  
  <p>and this as well</p>
  
  <pre class="lang-cs prettyprint-override"><code>String.Format("javascript:$find('{0}').show();", ModalPopupExtender1))
  String.Format("javascript:$find('{0}').show();", ModalBehavior))
  </code></pre>
  
  <p>When the gridview row is clicked I get the following error:</p>
  
  <blockquote>
    <p>Error: 'null' is null or not an object</p>
  </blockquote>
  
  <p>I have also tried implementing: <a href="https://stackoverflow.com/questions/996910/trouble-getting-a-reference-to-a-modalpopupextender-using-javascript">Trouble getting a reference to a ModalPopupExtender using javascript</a></p>
  
  <pre class="lang-js prettyprint-override"><code>function pageLoad() {
      var mpe = $find('ModalBehavior');
      mpe.show();
      debugger;
      $find('ModalBehavior').add_showing(
          function () {
              alert("Modal Popup will be showing");
          }
      );
  }
  </code></pre>
  
  <p>but got the same results. Any help would be greatly appreciated.</p>