2009-06-15 51 views
0

我想使用下面的代碼來獲取對modalpopupextender的引用,但是當我檢查javascript變量'modal'的值時,它始終爲空。使用javascript獲得對AJAX控件的引用的正確方法是什麼?使用javascript無法獲取對ModalPopupExtender的引用

的.vb

 Dim myStringBuilder As New StringBuilder(246) 
     myStringBuilder.AppendFormat("  <script type=""text/javascript"">{0}", Environment.NewLine) 
     myStringBuilder.AppendFormat("   var modal = $find('<%=modal1.ClientID%>');{0}", Environment.NewLine) 
     myStringBuilder.AppendFormat("   debugger;{0}", Environment.NewLine) 
     myStringBuilder.AppendFormat("   $find('<%=modal1.ClientID%>').add_showing({0}", Environment.NewLine) 
     myStringBuilder.AppendFormat("    function(){0}", Environment.NewLine) 
     myStringBuilder.AppendFormat("    {{{0}", Environment.NewLine) 
     myStringBuilder.AppendFormat("     alert(""Modal popup will be showing"");{0}", Environment.NewLine) 
     myStringBuilder.AppendFormat("    }}{0}", Environment.NewLine) 
     myStringBuilder.AppendFormat("   );{0}", Environment.NewLine) 
     myStringBuilder.AppendFormat("  </script>{0}", Environment.NewLine) 
     ClientScript.RegisterStartupScript(Me.GetType(), "myJSalert", myStringBuilder.ToString()) 

的.aspx

 <ajaxToolkit:ModalPopupExtender ID="mpeResetConfirm" runat="server" 
     TargetControlID="btnReset" PopupControlID="pnlConfirmation" BehaviorID="modal1"/> 

回答

1

我懷疑問題的一部分是在腳本被調用時沒有渲染出popupextender。所以谷歌搜索後,我發現這個職位:http://forums.asp.net/p/1413275/3112082.aspx#3112082。這裏是我結束瞭解決方案:

的.aspx

<ajaxToolkit:ModalPopupExtender ID="mpeResetConfirm" runat="server" 
    TargetControlID="btnReset" PopupControlID="pnlConfirmation" BehaviorID="modal1"/> 
    <script type="text/javascript" language="javascript"> 
     function pageLoad() 
     { 
      var modal = $find('modal1'); 
      debugger; 
      $find('modal1').add_showing(
       function() 
       { 
        alert("Modal popup will be showing"); 
       } 
      ); 
     } 
    </script> 
0

嘗試

$find('IDofModalPopupExtender') 

,而不是

$find('<%=modal1.ClientID%>') 
+0

我得到這個錯誤:「空」爲空或不是一個對象 – swolff1978 2009-06-15 16:27:03

+0

你與你的擴展的ID替換「IDofModalPopupExtender」?另外,你從哪裏得到'null'? – 2009-06-15 16:31:46

相關問題