将 ModalPopupExtender TargetControlID 设置为 LIstView 按钮
Setting ModalPopupExtender TargetControlID to LIstView Button
我想知道如何将 ModalPopupExtender
的 TargetControlID
设置为 ListView
上的按钮。
我试图将 TargetControlID
设置为的按钮位于 ListView 的交替和项目模板中。所以我相信我需要将 TargetControlID
设置为两个按钮,或者有两个不同的 ModalPopupExtenders
.
这是我的 ModalPopupExtender
:
<cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panl1" TargetControlID="Button1"
CancelControlID="Button2" BackgroundCssClass="Background" OnLoad="mp1_Load">
</cc1:ModalPopupExtender>
这是我的列表视图的交替模板:
<AlternatingItemTemplate>
<!--Input fields that do not apply to the question-->
..
..
..
<asp:Button ID="Button1" runat="server" Text="Show Popup" />
</AlternatingItemTemplate>
这与 ItemTemplate 的设置完全相同。
您可以使用 java-script 代替:
<a id="showModalPopupClientButton" href="#">Open pop-up</a>
<a id="hideModalPopupViaClientButton" href="#">Close pop-up</a>
<script type="text/javascript">
// Add click handlers for buttons to show and hide modal popup on pageLoad
function pageLoad() {
$addHandler($get("showModalPopupClientButton"), 'click', showModalPopupViaClient);
$addHandler($get("hideModalPopupViaClientButton"), 'click', hideModalPopupViaClient);
}
function showModalPopupViaClient(ev) {
ev.preventDefault();
var modalPopupBehavior = $find('programmaticModalPopupBehavior');
modalPopupBehavior.show();
}
function hideModalPopupViaClient(ev) {
ev.preventDefault();
var modalPopupBehavior = $find('programmaticModalPopupBehavior');
modalPopupBehavior.hide();
}
</script>
更新(使用服务器端)
您需要先设置一个伪造的服务器按钮(显示:none)作为弹出扩展器的目标控件 ID:
<asp:Button ID="Button1" runat="server" Style="display: none;" />
<cc1:ModalPopupExtender ID="mp1" runat="server"
PopupControlID="Panl1" TargetControlID="Button1"
CancelControlID="Button2" BackgroundCssClass="Background"
OnLoad="mp1_Load">
</cc1:ModalPopupExtender>
在你后面的代码中,当你想显示或关闭弹出窗口时,你只需要调用以下函数:
mp1.Show(); //to display popup
mp1.Hide() //to close popup
我想知道如何将 ModalPopupExtender
的 TargetControlID
设置为 ListView
上的按钮。
我试图将 TargetControlID
设置为的按钮位于 ListView 的交替和项目模板中。所以我相信我需要将 TargetControlID
设置为两个按钮,或者有两个不同的 ModalPopupExtenders
.
这是我的 ModalPopupExtender
:
<cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panl1" TargetControlID="Button1"
CancelControlID="Button2" BackgroundCssClass="Background" OnLoad="mp1_Load">
</cc1:ModalPopupExtender>
这是我的列表视图的交替模板:
<AlternatingItemTemplate>
<!--Input fields that do not apply to the question-->
..
..
..
<asp:Button ID="Button1" runat="server" Text="Show Popup" />
</AlternatingItemTemplate>
这与 ItemTemplate 的设置完全相同。
您可以使用 java-script 代替:
<a id="showModalPopupClientButton" href="#">Open pop-up</a>
<a id="hideModalPopupViaClientButton" href="#">Close pop-up</a>
<script type="text/javascript">
// Add click handlers for buttons to show and hide modal popup on pageLoad
function pageLoad() {
$addHandler($get("showModalPopupClientButton"), 'click', showModalPopupViaClient);
$addHandler($get("hideModalPopupViaClientButton"), 'click', hideModalPopupViaClient);
}
function showModalPopupViaClient(ev) {
ev.preventDefault();
var modalPopupBehavior = $find('programmaticModalPopupBehavior');
modalPopupBehavior.show();
}
function hideModalPopupViaClient(ev) {
ev.preventDefault();
var modalPopupBehavior = $find('programmaticModalPopupBehavior');
modalPopupBehavior.hide();
}
</script>
更新(使用服务器端) 您需要先设置一个伪造的服务器按钮(显示:none)作为弹出扩展器的目标控件 ID:
<asp:Button ID="Button1" runat="server" Style="display: none;" />
<cc1:ModalPopupExtender ID="mp1" runat="server"
PopupControlID="Panl1" TargetControlID="Button1"
CancelControlID="Button2" BackgroundCssClass="Background"
OnLoad="mp1_Load">
</cc1:ModalPopupExtender>
在你后面的代码中,当你想显示或关闭弹出窗口时,你只需要调用以下函数:
mp1.Show(); //to display popup
mp1.Hide() //to close popup