twitter-bootstrap 从后面的代码显示引导模式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31398665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 22:56:54  来源:igfitidea点击:

show the bootstrap modal from code behind

c#asp.nettwitter-bootstrap

提问by omarmallat

I created an ASP.NET Web Application (webforms) using visual studio 2013. bootstrap has been created and working properly.

我使用 Visual Studio 2013 创建了一个 ASP.NET Web 应用程序(webforms)。引导程序已经创建并正常工作。

my plan is to show a modal dialog which work perfectly as below using data-target attribute:

我的计划是使用 data-target 属性显示一个模式对话框,如下所示:

<div id="confimDialog" class="modal fade" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Confirmation</h4>
            </div>
            <div class="modal-body">
                <p>Your request has been submitted successfully.</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">Ok</button>
            </div>
        </div>
    </div>
</div>
<asp:Button runat="server" Text="Submit" data-target="#confirmDialog" />

When I moved to the next step to show the confirmation from code behind, after executing some update in my database, the modal dialog never showed up:

当我转到下一步以显示来自后面代码的确认时,在我的数据库中执行了一些更新后,模态对话框从未出现:

protected void Submit_Click(object sender, EventArgs e)
{
    //my database codes here
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "Confirm();", true);
}

and for sure I added the following script to my aspx page:

并且可以肯定的是,我将以下脚本添加到了我的 aspx 页面:

<asp:Button runat="server" Text="Submit" CssClass="btn btn-primary" OnClick="Submit_Click" />
<script>
    function Confirm () {
        $('#confirmDialog').modal('show'); 
        return true;
    };
</script>

I spent two days in this problem without any solution... I saw that there are some problem in showing a modal dialog from code behind, while many people say it's working using this codes. could you please help in this or propose any alternative solution to show a confirmation dialog from code behind???

我在这个问题上花了两天没有任何解决方案......我看到从代码后面显示模态对话框有一些问题,而很多人说它使用这些代码工作。你能帮忙解决这个问题或提出任何替代解决方案来显示来自代码背后的确认对话框吗???

references:bootstrap modal problem in code behind

参考文献:隐藏代码中的引导模式问题

thanks.

谢谢。

回答by Richard

I figured out that if you move this two lines to the top ( inside the header ) it works,

我发现如果你将这两行移到顶部(在标题内)它会起作用,

 <script src="https://code.jquery.com/jquery.js"></script>
 <script src="Scripts/bootstrap.js"></script>

most of the people recommend put this two lines at the end, before the body ends, but I moved them to the header and it works.

大多数人建议将这两行放在最后,在正文结束之前,但我将它们移到标题中并且它有效。