gpt4 book ai didi

c# - Asp.net 从后面的代码加载框架 src

转载 作者:行者123 更新时间:2023-11-30 17:36:34 24 4
gpt4 key购买 nike

在单击按钮时从后面的代码设置我的框架 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;

将在以模式加载的页面中使用 Str ID。还有什么其他选项或我还能做什么。

最佳答案

从 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>

如果您的应用程序中不存在 session leaveid,则在代码隐藏文件中创建 session leaveid

关于c# - Asp.net 从后面的代码加载框架 src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39241554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com