private static byte[] GetBytes(Control control, bool scriptsOnly) { MemoryStream renderedControlText = new MemoryStream(); StreamWriter sw = new StreamWriter(renderedControlText); HtmlTextWriter textWriter = new HtmlTextWriter(sw); if (scriptsOnly) // this is a response to a databox script request { List <JsonControl> jsonControls = BoxUserControl.GetAllJsonControls(control); foreach (JsonControl jsonControl in jsonControls) { jsonControl.RenderScripts = true; jsonControl.RenderConglomerateScript(textWriter, false); } } else { control.RenderControl(textWriter); } textWriter.Flush(); byte[] htmlBytes = new byte[renderedControlText.Length]; renderedControlText.Seek(0, 0); renderedControlText.Read(htmlBytes, 0, (int)renderedControlText.Length); return(htmlBytes); }
private static Control LoadControl(string virtualBoxPath, bool renderScripts, string requesterId, object injectionObject, bool postWindowLoad) { JavascriptPage controlLoader = new JavascriptPage(); Control control = controlLoader.LoadControl(virtualBoxPath); //if (control.Controls.Count == 0) // throw new UserControlIsNotBoxUserControlException(virtualBoxPath); BoxUserControl evolved = control as BoxUserControl;//control.Controls[0] as BoxUserControl; if (evolved == null) { throw new UserControlIsNotBoxUserControlException(virtualBoxPath); } Type controlType = control.GetType(); JavascriptServer.RegisterProvider(controlType);// makes any JsonMethod methods available to the client controlLoader.Controls.Add(control); if (injectionObject != null) { MethodInfo boxInject = CustomAttributeExtension.GetFirstMethodWithAttributeOfType <BoxInject>(controlType); if (boxInject != null) { ParameterInfo[] paramInfo = boxInject.GetParameters(); if (paramInfo.Length != 1 || paramInfo[0].ParameterType != injectionObject.GetType()) { throw ExceptionHelper.CreateException <JsonInvalidOperationException>("The BoxInject method of control type {0} has the wrong type or number of parameters.", control.GetType().Name); } boxInject.Invoke(control, new object[] { injectionObject }); } evolved.Inject(injectionObject); } MethodInfo boxInit = CustomAttributeExtension.GetFirstMethodWithAttributeOfType <BoxInit>(control.GetType()); if (boxInit != null) { boxInit.Invoke(control, null); } evolved.PostBoxLoad(renderScripts, requesterId, postWindowLoad); //loadedControls.Add(virtualBoxPath, control); return(control); }