0

我正在尝试使用以下代码来获取对 modalpopupextender 的引用,但是当我检查 javascript 变量 'modal' 的值时,它始终为空。使用 javascript 获取对 AJAX 控件的引用的正确方法是什么?

.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"/> 
4

2 回答 2

1

我怀疑部分问题是在调用脚本时没有渲染 popupextenders。所以在谷歌搜索后,我发现了这篇文章: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>
于 2009-06-15T17:25:51.933 回答
0

尝试

$find('IDofModalPopupExtender')

代替

$find('<%=modal1.ClientID%>')
于 2009-06-15T16:15:47.680 回答