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:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...