ModalPopupExtender - 如何仅在满足某些条件时显示? [英] ModalPopupExtender - how to show only when certain conditions are met?

查看:66
本文介绍了ModalPopupExtender - 如何仅在满足某些条件时显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ModalPopupExtender.Onclick按钮(这是ModalPopupExtender的TargetControlID),调用检查某些条件的javascript.我的要求是,只有在某些条件为真时才显示弹出窗口,否则隐藏它.

I am working with ModalPopupExtender. Onclick of button (which is TargetControlID of ModalPopupExtender), calls javascript which checks for some conditions. My requirement is, i want to show popup only if certain condition is true, otherwise hide it.

这是代码.隐藏功能在这里不起作用.即使调用 hide() 也会出现弹出窗口.

Here is the code. Hide function is not working here. Popup appears even if hide() is called.

function ShowAlert()
{
    if (selBtn == "" || selBtn == null)
    {
        alert("Please select scrip/scheme first");
        var modalPopup = $find('<%=ModalPopupExtender2.ClientID %>');
        if (modalPopup != null)
        {
            modalPopup.hide();
        }
        return false;
    }
}

-----------------------------------------------

<table width="100%" border="0" cellpadding="0" cellspacing="0">
   <tr>
     <td valign="top" align="center">
       <asp:Button ID="btnSet" runat="server" Text="Set Alerts" OnClientClick="ShowAlert();" />
       <cc1:ModalPopupExtender ID="ModalPopupExtender2" runat="server" BehaviorID="ModalBehaviour2" TargetControlID="btnSet" PopupControlID="pnlPopupU" DropShadow="false" X="100" Y="200" BackgroundCssClass="Inactive"></cc1:ModalPopupExtender>
     </td>
   </tr>
</table>

推荐答案

在代码后面你可以:

if (true)
{
var script = @"Sys.Application.add_load(function() { $find('behavoirIDModal').show(); });";
ScriptManager.RegisterStartupScript(this, GetType(), "ShowPopup", script, true);
}

并在 aspx 中创建:

and in aspx you make:

   <asp:Panel runat="server" ID="pnlSalvo">
        <asp:Button ID="btnClose" runat="server" Text="Fechar" />
    </asp:Panel>
    <ajaxToolkit:ModalPopupExtender ID="ModalResultado" BehaviorID="acao" runat="server" PopupControlID="pnlSalvo"
        TargetControlID="btnShow"
        CancelControlID="btnClose">
    </ajaxToolkit:ModalPopupExtender>
    <asp:Button ID="btnShow" runat="server" Text="Modal" Visible="true"  />

这篇关于ModalPopupExtender - 如何仅在满足某些条件时显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆