I've got a page where I have a ModalPopUpExtender which I want to show from code.
我有一个页面,我有一个ModalPopUpExtender,我想从代码中显示。
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 also 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.
find方法始终返回null。我也试过findComponent等。它总是为null。当我调试方法时,我注意到组件集合(它是一种控件ID为键的字典)是空的。
What could the problem be? BTW, I am using jQuery stuff on the page as well.
问题是什么?顺便说一句,我也在页面上使用jQuery的东西。
Thanks a lot!
非常感谢!
2 个解决方案
#1
0
Ok I found it. The TargetControl was not rendered in HTML because it was in another view.
好的,我找到了。 TargetControl未在HTML中呈现,因为它位于另一个视图中。
#2
0
In your JavaScript function try using document.getElementById("ctl00_ContentPlaceHolder1_newAddressModalPopup")
. Maybe it works. Let me know if you get issues.
在JavaScript函数中尝试使用document.getElementById(“ctl00_ContentPlaceHolder1_newAddressModalPopup”)。也许它有效。如果你遇到问题,请告诉我。
Or try Setting BehaviorID="someid"
to the modal popupextender and use this JavaScript code:
或者尝试将BehaviorID =“someid”设置为modal popupextender并使用此JavaScript代码:
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();
}
#1
0
Ok I found it. The TargetControl was not rendered in HTML because it was in another view.
好的,我找到了。 TargetControl未在HTML中呈现,因为它位于另一个视图中。
#2
0
In your JavaScript function try using document.getElementById("ctl00_ContentPlaceHolder1_newAddressModalPopup")
. Maybe it works. Let me know if you get issues.
在JavaScript函数中尝试使用document.getElementById(“ctl00_ContentPlaceHolder1_newAddressModalPopup”)。也许它有效。如果你遇到问题,请告诉我。
Or try Setting BehaviorID="someid"
to the modal popupextender and use this JavaScript code:
或者尝试将BehaviorID =“someid”设置为modal popupextender并使用此JavaScript代码:
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();
}