开发者

ASP.NET Ajax Find Component Problem

I've got a page where I have a ModalPopUpExtender which I want to show from code.

This is my site structure which is a web form within a nested masterpage:

    ...
    <asp:Content ID="con" ContentPlaceHolderID="mainContent" runat="server">
        <asp:MultiView ID="tabMultiView" runat="server">
            <asp:View ID="generalTab" runat="server">
                <asp:ScriptManager ID="scriptManager"  runat="server">
                </asp:ScriptManager>

                <ajaxToolkit:ModalPopupExtender ID="newAddressModalPopup" CancelControlID="newAddressDialogCancelButton"
                    BackgroundCssClass="modalBackground" TargetControlID="newAddressLink" PopupControlID="newAddressDialogDiv"
                    runat="server">
                </ajaxToolkit:ModalPopupExtender>
                ...

                <a href="" onclick="openNewAddressDialog()">open dialog</a>

               <script type="text/javascript">


                    function openNewAddressDialog() {
                        $find('<%= newAddressModalPopup.ClientID %>').show();
                    }
                </script>
...

The find method always returns null. I al开发者_StackOverflow社区so tried findComponent, etc. It's always null. When I debugged the method I noticed that the components collection (which is kind of a dictionary with the control ID as key) is empty.

What could the problem be? BTW, I am using jQuery stuff on the page as well.

Thanks a lot!


Ok I found it. The TargetControl was not rendered in HTML because it was in another view.


In your JavaScript function try using document.getElementById("ctl00_ContentPlaceHolder1_newAddressModalPopup"). Maybe it works. Let me know if you get issues.

Or try Setting BehaviorID="someid" to the modal popupextender and use this JavaScript code:

function changeValue()
{
    var myBehavior = $find("myBehavior1");
    myBehavior.show();
}

Or:

var modalDialog = $find("newAddressModalPopup"); 
// Get reference to modal popup using the Ajax API $find() function.

 if (modalDialog != null) {
     modalDialog.show();
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜