从后面的代码加载框架src

本文关键字:加载 框架 src 代码 | 更新日期: 2023-09-27 18:04:55

我有问题设置我的框架SRC从代码后面使用我的模态按钮点击。框架SRC正在获取值,但没有在模态中显示页面。模态代码

         <div class="modal fade " id="modal-info" role="dialog" data-keyboard="false"               style="border: none; height: 500px;" >
         <div class="modal-dialog col-md-push-1">
        <!-- Modal content-->
        <div class="modal-content" style="width: 700px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Set Leave</h4>
            </div>
            <div class="modal-body">
                <iframe id="frm" runat="server" width="96.6%" style="border: none; height: 300px;"></iframe>
            </div>
            <div class="modal-footer">
                <button type="button" id="Button2" class="btn btn-primary" data-dismiss="modal" runat="server" onserverclick="close_ServerClick">OK</button>
            </div>
        </div>
    </div>
</div>

然后在代码后面点击按钮

   frm.Src = "../Popups/staff_leave_calender.aspx";
   ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "$('#modal-info').modal();", true);

只有当帧SRC设置在页面加载

时才有效
     protected void Page_Load(object sender, EventArgs e)
    {
        frameinfo.Src = "../Popups/staff_leave_calender.aspx";
    }

,我需要做一些像

         Session["leaveid"] = StrID;
       frameinfo.Src = "../Popups/staff_leave_calender.aspx?lvv=" + StrID;

将在modal中加载的页面中使用Str ID。

从后面的代码加载框架src

从javascript完整代码中使用它在你的aspx文件中添加顶部脚本

  <script type="text/javascript">
    $(document).ready(function () {
        /* Get iframe src attribute value i.e. YouTube video url
        and store it in a variable */
        var url = "../Popups/staff_leave_calender.aspx?lvv="+"<%= Session["leaveid"].ToString() %>";
        /* Assign empty url value to the iframe src attribute when
        modal hide, which stop the video playing */
        document.getElementById("<%= btnAlelrt.ClientID %>").on('hide.bs.modal', function () {
            $("#frm").attr('src', '');
        });
        /* Assign the initially stored url back to the iframe src
        attribute when modal is displayed again */
        document.getElementById("<%= btnAlelrt.ClientID %>").on('show.bs.modal', function () {
            $("#frm").attr('src', url);
        });
    });
</script>

和后面的代码文件创建会话leaveid,如果它不存在于您的应用程序