Example #1
0
        internal void RenderCallback(Stream next, MemoryStream content)
        {
            // rendering an ajax callback
            if (string.IsNullOrEmpty(_redirectUrl))
            {
                // response was not redirected
                InternalJavaScriptWriter.Flush();
                _internalJavaScriptMemStream.Flush();
                _internalJavaScriptMemStream.Position = 0;

                using (TextReader readerContent = new StreamReader(_internalJavaScriptMemStream))
                {
                    string allContent = readerContent.ReadToEnd();
                    using (TextWriter writer = new StreamWriter(next))
                    {
                        AddDynamicScriptIncludes(writer);
                        writer.WriteLine(allContent);

                        SetViewState(content, writer);

                        JavaScriptWriter.Flush();
                        _javaScriptMemStream.Flush();
                        _javaScriptMemStream.Position = 0;

                        using (TextReader readerContent2 = new StreamReader(_javaScriptMemStream))
                        {
                            string allContentAtBack = readerContent2.ReadToEnd();
                            writer.WriteLine(allContentAtBack);
                        }

                        writer.Flush();
                    }
                }
            }
        }
Example #2
0
        private void AddMuxInitScripts(StringBuilder builder)
        {
            builder.Append("<script type=\"text/javascript\">");
            builder.Append("//<![CDATA[\r\nfunction MUXUnload(){MUX.Ajax._pageUnloads = true;}function MUXInit() {");

            InternalJavaScriptWriter.Flush();
            _internalJavaScriptMemStream.Flush();
            _internalJavaScriptMemStream.Position = 0;
            using (TextReader readerContent = new StreamReader(_internalJavaScriptMemStream))
            {
                string allContent = readerContent.ReadToEnd();
                builder.Append(allContent);

                JavaScriptWriter.Flush();
                _javaScriptMemStream.Flush();
                _javaScriptMemStream.Position = 0;
                using (TextReader readerPublicScripts = new StreamReader(_javaScriptMemStream))
                {
                    string allContentAtBack = readerContent.ReadToEnd();
                    builder.Append(allContentAtBack);
                }

                // Adding script closing element
                builder.Append("}(function(){if (window.addEventListener){window.addEventListener('load',MUXInit,false);" +
                               "window.addEventListener('unload',MUXUnload,false);}else{window.attachEvent('onload',MUXInit);" +
                               "window.attachEvent('onunload',MUXUnload);}})();");

                foreach (string idxScript in _scriptIncludes)
                {
                    string script = idxScript;
                    if (idxScript.IndexOf("end:") == 0)
                    {
                        script = idxScript.Substring(4);
                    }
                    builder.AppendFormat("MUX._scripts['{0}']=true;", script.Replace("&", "&amp;"));
                }
                builder.Append("\r\n//]]>\r\n</script>");
            }
        }