将查询字符串值从页面传递 asp.net 到 iframe

passing query string value from asp.net page to iframe

本文关键字:asp net iframe 字符串 查询      更新时间:2023-09-26

我有一个带有文本框和按钮的 asp.net 页面。 单击按钮时,我打开一个弹出窗口并使用 iframe 在其中加载一个页面。我想将文本框的值作为查询字符串传递到 iframe 中的页面。我该怎么做?

我尝试像这样使用服务器端 iframe:

<iframe id="popupframe" runat="server" src="~/temp.aspx" width="100%" height="455">
            </iframe>     

但是 temp.aspx 不加载并给出 404。如果我在没有服务器端标签的情况下使用它

<iframe id="popupframe"  src="../../../../temp.aspx" width="100%" height="455">
            </iframe>     

页面在 iframe 中加载,但我无法将文本框的值传递给 temp.aspx。请提出解决方案。谢谢

temp.aspx 绝对是您网站的根源吗?404错误通常非常清楚地表明您要查找的东西不存在!事实上,您在工作的纯HTML版本中有一个相对路径,这使我认为您的服务器端版本的路径可能存在问题。

作为替代方案,您可以将查询字符串传递给弹出页面,并在该页面上使用一些 javascript 来操作 iframe 的 src 属性。

例如(弹出页面上的脚本(

var qs = window.location.search; // Gets the entire querystring - not very obvious!
var iframe = document.getElementById("popupframe");
iframe.src += qs; // Adds the querystring on to the end of the iframe's src.

您希望在加载页面内容后运行它。我不知道你使用的是jQuery还是其他框架(或者没有框架!(,所以我不会讨论如何做到这一点(但如果你需要我,可以(。

试试这个:

<iframe id="popupframe" runat="server" src="<%= Page.ResolveUrl("~/temp.aspx") %>" width="100%" height="455">
            </iframe> 

我用了这个

代码隐藏在按钮上 单击事件

this.iframRfer.Attributes["src"] = "visit_opd_refer.aspx?regnn="+opdNo; 姆波普。显示((;

 <% Int64 ss =Convert.ToInt64( Request.QueryString["id"].ToString());%>
 <% string bb = ss.ToString().Insert(0, "testing.aspx?id="); %>
  <iframe    src="<%=bb %>"   style="height: 100%; width: 100%; border: 2px;"> 
 </iframe>

不需要任何脚本。这也是一种格式。