示例#1
0
 internal void InitializePage(BaseControl ctrl)
 {
     MuxControls.Add(ctrl);
     if (MuxControls.Count == 1)
     {
         // we only run this logic once
         // basically we're adding up the callback filter for custom response rendering
         if (IsAjaxCallback)
         {
             Page.LoadComplete   += LoadComplete_Ajax_Callback;
             Page.Response.Filter = new AjaxFilter(Page.Response.Filter);
         }
         else
         {
             Page.LoadComplete   += Page_Load_No_Ajax;
             Page.Response.Filter = new ResponseFilter(Page.Response.Filter);
         }
     }
 }
示例#2
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);
        }