tags:

views:

266

answers:

1

Hello,

I've created one aspx page Default.aspx. It contains iframe with child.aspx. File Child.cs contains web methods which should be called by parent page.

As I understand I need to receive the instance of Child class so then I'll be able to them call. How can I make this?

I will be really appreciated for constructive solution,

Default.aspx (Parent page)

<%@ 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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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;
        }
    }
}

So How I can call getResultData () from Child.aspx.cs by clicking Button on the parent page. The main difficulty is that I can't use Javascript to collect the information from TextBoxes because the task is more complicated and I can use only server methods.

Thank you in advance, Best wishes, Greg.

A: 

Thats not really the way iframes work. Remember, HTTP is a stateless protocol, which means that each request for a page is an independent request, and won't have any context of the previous request. What I think you would need to do, is either request the Child.aspx page with specific form or request variables, and the Child page should output the correct page accordingly.

Could you explain what it is you want to achieve?

Matthew Abbott
Hi,We've bought the component which provides with configuration the view by javascript, but to receive the result data you can only in codebehind (c#). Due to some specifics things I need to use iframes with this component and when I click to the button on the parent page I need to receive the information from iframe (call c# method from child.cs getResultdata();). That's why I ask you how I can receive the access to these data.Thank you in advance,Greg
Greg
Which component have you purchased?
Matthew Abbott
I can't say it, sorry.
Greg
Well, we can't really help you then...
Matthew Abbott
The main question is in the communication between child.aspx and parent one and that is all. Could you help me?
Greg
Without more information about what exactly you are trying to do, perhaps show us some code, I can't add any further comments...
Matthew Abbott
Matthew,I've added the code. I hope it helps,Thank you in advance,Greg.
Greg