コード例 #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();
                    }
                }
            }
        }
コード例 #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>");
            }
        }
コード例 #3
0
        private void LoadComplete_Ajax_Callback(object sender, EventArgs e)
        {
            // storing viewstate
            _requestViewState = Page.Request.Params["__VIEWSTATE"];

            // finding the control that startet the ajax callback
            string controlId = Page.Request.Params["magix.ux.callback-control"];

            Page.Response.ContentType = "text/javascript";

            if (string.IsNullOrEmpty(controlId))
            {
                // callback was initiated by a function invocation
                string function = Page.Request.Params["magix.ux.function-name"];

                if (string.IsNullOrEmpty(function))
                {
                    return;
                }

                Control    objectToInvokeOn = Page;
                MethodInfo method           = FindWebMethod(function, ref objectToInvokeOn);

                if (method == null || method.GetCustomAttributes(typeof(Magix.UX.Core.WebMethod), false).Length == 0)
                {
                    throw new Exception("cannot call a method without a 'WebMethod' attribute");
                }

                // extracting parameter values as correct types
                ParameterInfo[] parameters = method.GetParameters();
                List <object>   args       = new List <object>();
                for (int idxPar = 0;
                     idxPar < parameters.Length && Page.Request.Params["magix.ux.function-parameter" + idxPar] != null;
                     idxPar++)
                {
                    args.Add(Convert.ChangeType(
                                 Page.Request.Params["magix.ux.function-parameter" + idxPar],
                                 parameters[idxPar].ParameterType));
                }

                object retVal = method.Invoke(objectToInvokeOn, args.ToArray());
                if (retVal != null)
                {
                    string retValString = string.Format(CultureInfo.InvariantCulture, "{0}", retVal);
                    retValString = retValString.Replace("\\", "\\\\").Replace("'", "\\'");
                    JavaScriptWriter.Write("MUX.Control._functionReturnValue='{0}';", retValString);
                }
                return;
            }

            BaseControl evtCtrl = MuxControls.Find(
                delegate(BaseControl idx)
            {
                return(idx.ClientID == controlId);
            });

            if (evtCtrl == null)
            {
                throw new ApplicationException("oops, non-existing control initiated an ajax callback! wtf??");
            }

            string evtName = Page.Request.Params["magix.ux.event-name"];

            // Dispatching the event to our MUX Control...
            evtCtrl.RaiseEvent(evtName);
        }