从代码隐藏填充bootstrapdialog文本

时间:2017-09-27 19:21:48

标签: asp.net vb.net code-behind

在代码隐藏中设置弹出窗口的文本时遇到问题,它会刷新页面,这意味着弹出窗口会消失。

我尝试过一个示例/教程,但似乎无法让它发挥作用。我试过移动更新面板,并在按钮上使用autopostback = false。我确定它有点傻,但我无法看到它..

这是我的aspx页面;

constructor(
        protected route: ActivatedRoute,
        protected recipesService: RecipesService) {
        super(route)
    }

这是我的代码隐藏VB.NET;

<%@ Page Language="vb" AutoEventWireup="false" 
CodeBehind="ShowDialog.aspx.vb" Inherits="BootStrapDialog.WebForm1" 
MaintainScrollPositionOnPostBack="true" %>

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"
    rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div class="container">
    <div class="row">
        <h1>
            Hello, world! Hello, world!</h1>
        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>

        <asp:Button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" Text="Launch demo modal" OnClick="GenerateModalText" runat="server">

        </asp:Button>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <!-- Modal -->
                <asp:Label ID="Label1" runat="server" Text=""></asp:Label><br />
                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
                    aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel">
                                    Modal title</h4>
                            </div>
                            <div class="modal-body">
                                <asp:TextBox ID="TextBox1" runat="server" class="form-control"></asp:TextBox><br />
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">
                                    Close</button>
                                <%--<button type="button"  class="btn btn-primary">
                                    Save changes</button>--%>
                                <asp:Button Text="Save" OnClick="Submit" runat="server" />
                            </div>
                        </div>
                    </div>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</div>
</form>

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

根据您是否动态绑定模态,您有两种解决方案之一。

首先,您可以注册启动脚本,以便在页面重新加载时打开模式。

                Page.ClientScript.RegisterStartupScript(GetType(), "UpdateModal", string.Format("OpenModal(\"{0}\", \"{1}\");", "modal-blank", "static"), true);

我有一些框架来打开我的模态,但用引导模式打开代码替换javascript函数,它应该可以工作。

其次,您可以在Page_Load事件期间重新绑定模态。

基本上,一旦按下按钮,整个页面在触发按钮事件之前会再次经历它的生命周期。如果你没有绑定模态,页面就不知道它是否存在以设置文本。