ASP.NET代码后台从frame src加载

3

我遇到了一个问题,即从代码后端设置我的框架src以在单击按钮时在我的模态中使用。frame 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;

在模态框中加载的页面中将使用 Str ID。其他选项或其他可做的事情是什么。

1个回答

1

使用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,则创建该会话。


会话只能在按钮点击时获取。 - Damilare joshua
int StrID = (int)e.Appointment.ID; Session["leaveid"] = StrID; 将预约的ID转换为整数类型并赋值给StrID变量,然后将StrID存储在会话变量"leaveid"中。 - Damilare joshua
1
尝试一下,我认为它会起作用,因为我有同样的代码用于YouTube视频弹出窗口,而且它运行良好。 - Ankit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接