Think about the difference between client code and server code. Server code runs through to completion, the resulting markup is sent to the client, then the client side code runs. So popping up a modal from server side code, followed by a redirect, isn't going to work. It's going to redirect the client, and the client will never execute any markup because the redirect is performed immediately.
Instead, you need to use client side code to handle the bootstrap modal closing event and perform the redirect.
$('#myBS_Modal').on('hidden.bs.modal', function (e) {
window.location = '<%= ResolveUrl("~/aaa.aspx")>';
});
Change
<script type="text/javascript">
function ShowPopup() {
$("#btnBS_Modal").click();
}
</script>
to
<script type="text/javascript">
function ShowPopup() {
$("#btnBS_Modal").click();
}
$('#myBS_Modal').on('hidden.bs.modal', function (e) {
window.location = '<%= ResolveUrl("~/aaa.aspx") %>';
});
</script>
and get rid of your server side code that performs the redirect.
Since you can't use inline code, try this:
<asp:HiddenField runat="server" id="RedirectUrlHf" ClientIdMode="static" />
/* Inside your script tag */
$('#myBS_Modal').on('hidden.bs.modal', function (e) {
var url = $("#RedirectUrlHf").val();
window.location = url;
});
And on Page_Load, add this.
RedirectUrlHf.Value = ResolveUrl("~/aaa.aspx");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…