Example #1
0
        internal void InitializeControl(RaControl ctrl)
        {
            // We store all Ra Controls in a list for easily access later down the road...
            RaControls.Add(ctrl);

            // Making sure we only run the initialization logic ONCE...!!
            if (RaControls.Count == 1)
            {
                if (((Page)HttpContext.Current.CurrentHandler).Request.Params["HTTP_X_MICROSOFTAJAX"] != null)
                {
                    return;
                }

                if (IsCallback)
                {
                    // This is a Ra-Ajax callback, we need to wait until the Page Load
                    // events are finished loading and then find the control which
                    // wants to fire an event and do so...
                    ((Page)HttpContext.Current.CurrentHandler).LoadComplete += CurrentPage_LoadComplete;

                    // Checking to see if the Filtering logic has been supressed
                    if (!SupressAjaxFilters)
                    {
                        ((Page)HttpContext.Current.CurrentHandler).Response.Filter = new CallbackFilter(((Page)HttpContext.Current.CurrentHandler).Response.Filter);
                    }
                }
                else
                {
                    ((Page)HttpContext.Current.CurrentHandler).LoadComplete += CurrentPage_LoadComplete_NO_AJAX;

                    // Checking to see if the Filtering logic has been supressed
                    if (!SupressAjaxFilters)
                    {
                        ((Page)HttpContext.Current.CurrentHandler).Response.Filter = new PostbackFilter(((Page)HttpContext.Current.CurrentHandler).Response.Filter);
                    }
                }
            }
        }
Example #2
0
        private void CurrentPage_LoadComplete(object sender, EventArgs e)
        {
            // Storing request viewstate in order to be able to "diff"
            // them in rendering of response
            _requestViewState = ((Page)HttpContext.Current.CurrentHandler).Request.Params["__VIEWSTATE"];

            // Finding the Control which initiated the request
            string idOfControl = ((Page)HttpContext.Current.CurrentHandler).Request.Params["__RA_CONTROL"];

            // Setting Response Content-Type to JavaScript
            ((Page)HttpContext.Current.CurrentHandler).Response.ContentType = "text/javascript";

            // Checking to see if this is a "non-Control" callback...
            if (string.IsNullOrEmpty(idOfControl))
            {
                string functionName = ((Page)HttpContext.Current.CurrentHandler).Request.Params["__FUNCTION_NAME"];

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

                Control    ctrlToCallFor = ((Page)HttpContext.Current.CurrentHandler);
                MethodInfo webMethod     = ExtractMethod(functionName, ref ctrlToCallFor);

                if (webMethod == null || webMethod.GetCustomAttributes(typeof(Ra.WebMethod), false).Length == 0)
                {
                    throw new Exception("Cannot call a method without a WebMethod attribute");
                }

                ParameterInfo[] parameters = webMethod.GetParameters();

                object[] args = new object[parameters.Length];
                for (int idx = 0; idx < parameters.Length && ((Page)HttpContext.Current.CurrentHandler).Request.Params["__ARG" + idx] != null; idx++)
                {
                    args[idx] = Convert.ChangeType(((Page)HttpContext.Current.CurrentHandler).Request.Params["__ARG" + idx], parameters[idx].ParameterType);
                }

                object retVal = webMethod.Invoke(ctrlToCallFor, args);

                if (retVal != null)
                {
                    WriterAtBack.Write("Ra.Control._methodReturnValue='{0}';",
                                       string.Format(CultureInfo.InvariantCulture, "{0}", retVal).Replace("\\", "\\\\").Replace("'", "\\'"));
                }
                return;
            }

            RaControl ctrl = RaControls.Find(
                delegate(RaControl idx)
            {
                return(idx.ClientID == idOfControl);
            });

            // Getting the name of the event the control raised
            string eventName = ((Page)HttpContext.Current.CurrentHandler).Request.Params["__EVENT_NAME"];

            // Casting the initiated control to the interface expected all Ra Controls to be
            IRaControl raCtrl = ctrl as IRaControl;

            if (ctrl == null)
            {
                throw new ApplicationException("A control which was not a Ra Control initiated a callback, implement the IRaControl interface on the control");
            }

            // Dispatching the event to our Ra Control...
            raCtrl.DispatchEvent(eventName);
        }