2010-07-26 159 views
0

我創建了一個aspx頁面Default.aspx。它包含帶有child.aspx的iframe。文件Child.cs包含應該由父頁面調用的Web方法。從父aspx調用子iframe方法頁

據我所知,我需要接收Child類的實例,然後我才能夠給他們打電話。我怎樣才能做到這一點?

我會非常感激的建設性的解決辦法,

Default.aspx的(父頁)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Parent_Child_Iframe._Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:ScriptManager ID="ScriptManager1" runat="server"> 
     </asp:ScriptManager> 
     <asp:Button ID="btGetDataFromChild" runat="server" Text="Get Data from Child" /> 
     <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
      <ContentTemplate> 
       <iframe id="I1" height="300px" name="I1" src="child.aspx" width="400px"></iframe> 
      </ContentTemplate> 
     </asp:UpdatePanel> 
    </div> 
    </form> 
</body> 
</html> 

Child.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Child.aspx.cs" Inherits="Parent_Child_Iframe.Child" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
     <br /> 
     <br /> 
     <br /> 
     <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> 
    </div> 
    </form> 
</body> 
</html> 

Child.aspx.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

namespace Parent_Child_Iframe 
{ 
    public partial class Child : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 
     public string getResultData() 
     { 
      return TextBox1.Text + TextBox2.Text; 
     } 
    } 
} 

因此,如何通過單擊父頁面上的按鈕來從Child.aspx.cs中調用getResultData()。 主要的困難是我無法使用JavaScript從TextBoxes收集信息,因爲任務更復雜,我只能使用服務器方法。

謝謝你, 最好的祝福, 格雷格。

回答

0

這不是iframes的工作方式。請記住,HTTP是一種無狀態協議,這意味着對頁面的每個請求都是一個獨立請求,並且不會有任何前一個請求的上下文。我認爲你需要做的是要麼請求具有特定表單或請求變量的Child.aspx頁面,並且Child頁面應該相應地輸出正確的頁面。

你能解釋一下你想達到什麼嗎?

+0

嗨, 我們已經購買了組件,它提供了配置javascript的視圖,但接收結果數據只能在代碼隱藏(c#)中。由於一些具體事情我需要使用此組件的iframe,當我點擊父按鈕上的按鈕時,我需要從iframe(從child.cs getResultdata();調用c#方法)接收信息。這就是爲什麼我問你如何獲得這些數據。 預先感謝您, Greg – Greg 2010-07-26 15:08:59

+0

您購買了哪個組件? – 2010-07-26 16:04:03

+0

我不能說,對不起。 – Greg 2010-07-27 07:54:34