Saturday, August 14, 2010

How to load a iframe dynamically using jquery in code behind (C#)

<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head2" runat="server">    
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script runat="server">
        private string script = @"
            $(document).ready(function () {{
                $(""body"", $(""iframe#ifmContainer"").contents()).html(""{0}"");
            }});
        ";
        StringBuilder body = new StringBuilder();
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            ///
            /// Build your body html here...
            ///
            this.body.Append("<p>Hello World</p>");
            
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), 
                this.GetType().Name, string.Format(this.script, body), true);
        }
    </script>
</head>
<body>    
    <form id="form2" runat="server">  
        <iframe runat="server" id="ifmContainer" frameborder="0">
            <b>Your browser does not support iframes</b>
        </iframe>
    </form>
</body>
</html>

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...