Monday, September 13, 2010

How to create a popup window on the fly using java script in c# code behind

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head2" runat="server">
    <title>Test Page</title>
    <script runat="server">
        private string script = @"
          var popup =  
          window.open('','',
                'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
          popup.document.write(""{0}"");
  ";
        private StringBuilder body = new StringBuilder();
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            ///
            /// build your html document here
            ///
            body.Append("<html>");
            body.Append("<head></head>");
            body.Append("<body>");
            body.Append("<h1>Hello World</h1>");
            body.Append("<p>This is a popup window created on the fly");
            body.Append("</body>");
        }
        protected void OpenWindow(object sender, EventArgs e)
        {
            ///
            /// Check your condition
            ///
            bool myCondition = true;
            if (myCondition)
            {
                this.ClientScript.RegisterClientScriptBlock(
                 this.GetType(),
                 this.GetType().Name,
                 string.Format(this.script, this.body.ToString()),
                 true);
            }
        }        
    </script>
</head>
<body>
    <form id="form2" runat="server">
    <asp:LinkButton runat="server" ID="lnkButton" OnClick="OpenWindow" Text="Open a Window" />
    </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...