在javascript中打开模态弹出窗口

时间:2014-04-24 13:13:49

标签: javascript jquery c#-4.0 ajaxcontroltoolkit

的JavaScript

<script type="text/javascript">
    function example() {
        alert("dfszgvf");
        $find('Something').show();
    }
</script>

C#

protected void Page_Load(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(Page, GetType(), "JsStatus", "example();", true);
}

ASPX

     <form id="form1" runat="server">
    <div>

        <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></cc1:ToolkitScriptManager>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <cc1:ModalPopupExtender ID="ModalPopupExtender1"  runat="server" 
    BackgroundCssClass="modalBg" DropShadow="true" 
    PopupDragHandleControlID="Panel2" CancelControlID="btnCancel" 
    TargetControlID="lnkUpdate" OkControlID="btnOK" PopupControlID="Panel1"
    BehaviorID ="Something">
</cc1:ModalPopupExtender>

     <asp:LinkButton ID="lnkUpdate" ForeColor="#0000ff" Font-Bold="true" 
            Font-Underline="true" Font-Size="12px" runat="server">Click here to Change Text Style</asp:LinkButton>   
      <asp:Panel ID="Panel1" runat="server" CssClass="modalPanel" Style="display: none">
     <asp:Panel ID="Panel2" runat="server" style="border:solid 2px #cccccc; width:98%; cursor: move;">Drag Panel
     <div>
     ddddddddddddddddddddddddddddddddddd
     </div>
       <div class="right">
        <asp:Button ID="btnCancel" CssClass="button" runat="server" Text="[ X ]" />
        </div>
        <div class="left">
        <asp:Button ID="btnOK" runat="server" Text="OK Client Side" />
        </div>
        <div class="clear"></div>
    </asp:Panel>
    </asp:Panel>
    </ContentTemplate>
    </asp:UpdatePanel>

    </div>
    </form>

ModalPopupExtender在我使用链接按钮时有效,但在从.cs代码(在c#中)调用时无法正常工作。

有人可以帮我解决错误吗?...................................... .................................................. .................................................. ..........

1 个答案:

答案 0 :(得分:0)

你必须为模态弹出窗口设置 BehaviorID

<cc1:ModalPopupExtender ID="ModalPopupExtender1"  runat="server" 
    BackgroundCssClass="modalBg" DropShadow="true" 
    PopupDragHandleControlID="Panel2" CancelControlID="btnCancel" 
    TargetControlID="lnkUpdate" OkControlID="btnOK" PopupControlID="Panel1"
    BehaviorID ="Something">
</cc1:ModalPopupExtender>

然后使用:

var id= '<%= ModalPopupExtender1.BehaviorID %>';
$find('id').show();