如何从代码运行模式

本文关键字:运行 模式 代码 | 更新日期: 2023-09-27 18:37:02

我有一个模态,我想从我的模态后面的代码运行它:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>    
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <div dir="rtl" id="mymodal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalRapidAddLabel" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="float: left">×</button>
            <h3 id="myModalRapidAddLabel">Edit Brand</h3>
        </div>
        <div class="modal-body">
            <p>Enter New Name</p>
            <div class="control-group">
                <div class="controls">
                    <asp:TextBox ID="txtnewname" runat="server"></asp:TextBox>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">cancel</button>
        </div>
    </div></ContentTemplate>
</asp:UpdatePanel>

和我的代码隐藏:

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "none","<script>$('#mymodal').modal('show');</script>", false);
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "mymodal", "$('#mymodal').modal();", true);

每个我在哪里隐藏这个代码都必须运行模式,但这对我不起作用为什么?

如何从代码运行模式

试试这个,创建一个asp button

<asp:UpdatePanel runat="server">
                        <ContentTemplate>
                            <asp:Button runat="server" CssClass="btn btn-info" Text="Search" ID="cmdSearch" OnClick="cmdSearch_Click" />
                        </ContentTemplate>
                    </asp:UpdatePanel>

在代码隐藏中:

        protected void cmdSearch_Click(object sender, EventArgs e)
    {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "",
                "$('#mymodal').modal('show');", true);
    }