Tuesday, July 15, 2014

How to find control within iframe?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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>

    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
 
    <script type="text/javascript">
        function CheckFrame() {
            var x = document.getElementById("iframeID");
            var y = (x.contentWindow || x.contentDocument);
            if (y.document) y = y.document;
            alert($(y).find("#lblmessage").html());
            $(y).find("#lblmessage").html('22');
            return false;
        }

        // var frmPage = $("#iframeID").contentWindow;
        //var retVal = frmPage.ReturnVal();
    </script>
</head>
<body>
    <form id="form1" runat="server">
          <iframe id="iframeID" src="Default3.aspx" height="200px" width="200px"></iframe>
       <asp:Button ID="btn" runat="server" OnClientClick="return CheckFrame()" />
    </form>
</body>
</html>


=====================

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!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">
    <asp:TextBox ID="txt1" runat="server"></asp:TextBox>

    <asp:Label ID="lblmessage" runat="server" Text="123456"></asp:Label>
    </form>
</body>
</html>

No comments:

Post a Comment