asp.net的引导模式 - 收盘后重定向 [英] asp.net bootstrap modal - redirect after close

查看:120
本文介绍了asp.net的引导模式 - 收盘后重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的引导模式工作正常,但我不能找到一种方法单击模式关闭按钮后,重定向到另一个页面。结果
我的javascript:

my Bootstrap modal works fine but I can't find a way to redirect to another page after clicking the "Close" button in the modal.
My javascript :

<script src="/Content/Scripts/jquery.min.js" type="text/javascript"></script>
<script src="/Content/Scripts/bootstrap.min.js" type="text/javascript"></script>
<link href="~/Content/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="~/Content/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css" />
<link href="~/Content/css/myStyleSheet.css" rel="stylesheet" type="text/css" />
<link href="~/Content/Images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<asp:ContentPlaceHolder runat="server" ID="Head" />
<script type="text/javascript">
    function ShowPopup() { 
        $("#btnBS_Modal").click();
    }
</script>

我的HTML:

    <div class="container">
    <div class="row">
        <button type="button" style="display: none;" id="btnBS_Modal" class="btn btn-primary btn-lg"
            data-toggle="modal" data-target="#myBS_Modal" data-backdrop="static" data-keyboard="false">
            Launch demo modal</button>
        <div class="modal fade in" id="myBS_Modal">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                        <asp:Label ID="lblBS_Modal" runat="server"/>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-success " data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

我的code背后:

My code behind :

ClientScript.RegisterStartupScript(this.GetType(), "alert", "ShowPopup();", true);
this.lblBS_Modal.Text = "This is some message";
Response.Redirect("~/aaa.aspx");

在Respose.Redirect带我到正确的页面,但语气并不雨后春笋般冒出来的。结果
搜索了很多,但无法得到这个答案。

The "Respose.Redirect" takes me to the proper page, but the modal is not popping up at all.
Searched a lot but couldn't get an answer for this.

推荐答案

随着伟大和强大的@mason我终于得到它的工作的帮助。结果
我的母版:

With the help of the great and mighty @mason I finally got it to work.
My MasterPage:

<head runat="server">
    <meta charset="utf-8" />
    <title>Redirect - <%: Page.Title %></title>
    <script src="/Content/Scripts/myJavaScripts.js" type="text/javascript"></script>
    <script src="/Content/Scripts/jquery.min.js" type="text/javascript"></script>
    <script src="/Content/Scripts/bootstrap.min.js" type="text/javascript"></script>
    <link href="~/Content/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/css/myStyleSheet.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/Images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
</head>

注意,第一个环节是myJavaScripts.js里我把JS是:

Notice that the FIRST link is to "myJavaScripts.js" where I put the js which is:

function ShowPopup() {
    $("#btnBS_Modal").click();
    $('#myBS_Modal').on('hidden.bs.modal', function (e) {
        var url = $("#RedirectUrlHf").val();
        window.location = url;
    });
}

在那里的模态是页面的HTML,我有:

In the HTML of the page where the Modal is, I have :

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    </div>
    <div class="container">
        <asp:HiddenField ID="RedirectUrlHf" runat="server" ClientIDMode="Static" />
        <div class="row">
            <button type="button" style="display: none;" id="btnBS_Modal" class="btn btn-primary btn-lg"
                 data-toggle="modal" data-target="#myBS_Modal" data-backdrop="static" data-keyboard="false">
                Launch demo modal</button>
            <div class="modal fade in" id="myBS_Modal">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-body">
                            <asp:Label ID="lblBS_Modal" runat="server" />
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-success glyphicon glyphicon-ok" data-dismiss="modal"></button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>

(注意:这需要有hiddenfield 的ClientIDMode =静态)。

在我的code背后:

    protected void Page_Load(object sender, EventArgs e)
    {
        RedirectUrlHf.Value = ResolveUrl("/Account/aaa.aspx");
    }

现在,当我的页面上的模态关闭,我重定向到正确的页面。结果
@mason是一个很大的帮助,我在路上学到了很多东西从他身上。谢谢你,@mason。

Now when the modal on my page closes, I am redirected to the proper page.
@mason was a great help and I learned a lot from him on the way. Thank you, @mason.

这篇关于asp.net的引导模式 - 收盘后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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