2012-08-29 116 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();

相關問題