2012-08-29 118 views
0

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

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

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

但temp.aspx犯规负载,并给出404。如果我在iframe中使用它,而服务器端代码

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

页面加载,但我无法将文本框的值传递给temp.aspx。请建议解决方案。感谢

回答

0

在您的网站的根是temp.aspx肯定? 404错误通常是一个非常明显的迹象,表明你正在寻找的东西不在那里!事实上,在工作纯HTML版本中有一个相对路径,这让我认为服务器端版本的路径可能存在问题。

作为一种替代方法,您可以将querystring传递到弹出页面,并在该页面上使用一些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或其他框架(或没有框架!),所以我不会去怎么做(但可以,如果你需要我)。

+0

yes temp.aspx位于页面的根目录处,〜/ temp.aspx不起作用。弹出层次更深4层。 – DotnetSparrow

+0

我想做它服务器端。如果我想用javascript来做,我需要将上面的js代码添加到正在加载弹出窗口的页面或弹出窗口中打开的页面上吗? – DotnetSparrow

+0

对不起,我不希望遇到真正挑剔的挑剔,但你写了“在页面的根源”,这是不明确的,因为它是*站点*的根源,这很重要。为了让我放心,你能否确认,如果你在浏览器中输入“your.site.com/temp.aspx”,你会得到那个测试页面? – Jon

0

试试这个:

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

服务器标签不能包含<% ... %>结构。 – DotnetSparrow

+0

我的不好,错过了你的runat ='服务器'。然后将其设为常规的html iframe。没有好的理由让它拥有runat标签。 – Paul

+0

我尝试了它,并得到错误的请求错误。 – DotnetSparrow

0
<% 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> 

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

0

我用这个

Codebehid上按钮的单击事件

this.iframRfer.Attributes [ “SRC”] = “visit_opd_refer.aspx regnn =?” + opdNo; mpopup.Show();

相关问题