Sunday, March 11, 2012

Passing events between frames

You canuse __doPostBack() to trigger events in one frame from the other. Say you wanted to trigger an UpdatePanel, upContent in a frame named "content", you could do it with: parent.content.__doPostBack('upContent', '');


Hi,

SeePage Access within IFrame using Ajax.

When the user clicks on a button on Page B, You need to force an 'update panel' on Page A to do a postback (so it can refresh).

You can hide a button in page A, and set it to be a trigger of the updatepanel, then you can access to the button by using "window.parent.document.getElementById('Button1')" in page B.

Try the following codes,it works great:

Page A

<%@. Page Language="C#" %>

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

<script runat="server">

protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<div style="visibility:hidden"><asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" UseSubmitBehavior="false" /></div>
</ContentTemplate>
</asp:UpdatePanel>
<iframe src="http://pics.10026.com/?src=Default13.aspx" mce_src="Default13.aspx"></iframe>
</div>
</form>
</body>
</html>

Page B

<%@. Page Language="C#" %>

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

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" onclick="javascript:window.parent.document.getElementById('Button1').click();" name="Button1" value="Button" id="Button1" /></div>
</form>
</body>
</html>

Let me know if you need more info.

If this help you,don't forget mark it as a answer.Thanks!

Best Regards,


Thanks for the response.

I understand how this should work if I was using an iFrame, but since I'm using a frameset the only thing that returns with a window.parent.document call is my other frame (going with this example, window.parent.document.getElementByID can find Page A's frame, but not an element within page A itself). I've tried working my way down to find the button within page A's updatepanel but with no luck so far. Is there a way to go from Page B to a frameset index page to Page A's updatepanel? Any help is appreciated.


Hi,

It is the same!

Like this:

Index.html:

<html>
<frameset cols="25%,75%">
<frame src="http://pics.10026.com/?src=Default14.aspx"></frame>
<frame src="http://pics.10026.com/?src=Default15.aspx"></frame>
</frameset>
</html>

Default14.aspx

<%@. Page Language="C#" %>

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

<script runat="server">

protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<div style="visibility:hidden"><asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" UseSubmitBehavior="false" /></div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

Default15.aspx

<%@. Page Language="C#" %>

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

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" onclick="javascript:window.parent.document.frames[0].document.getElementById('Button1').click();" name="Button1" value="Button" id="Button1" /></div>
</form>
</body>
</html>

Best Regards,


Oh ok, I see now. I got it working, thank you for all of your helpBig Smile.

No comments:

Post a Comment