public void p5_web_return_response_object(ApplicationContext context, ActiveEventArgs e) { var key = XUtil.Single <string> (context, e.Args); var source = XUtil.Source(context, e.Args); AjaxPage.SendObject(key, Utilities.Convert <string> (context, source)); }
/* * Renders all controls that was added this request. */ void RenderAddedWidgets() { // Making sure all children rendered from this point are rendered as pure HTML. RenderMode = RenderingMode.ReRender; // Looping through all Controls, figuring out which were not there in the "_originalCollection", before it was changed, and retrieving their // HTML, such that we can pass it to the client, as a JSON insertion. foreach (var idx in Controls.Cast <Widget> ().Where(ix => !_originalCollection.Contains(ix) && !string.IsNullOrEmpty(ix.ID))) { // Getting control's HTML, by rendering it into a MemoryStream, and for then to pass it on as an "insertion" to our AjaxPage. using (var stream = new MemoryStream()) { using (var txt = new HtmlTextWriter(new StreamWriter(stream))) { idx.RenderControl(txt); txt.Flush(); } // Now we can read the HTML from our MemoryStream. stream.Seek(0, SeekOrigin.Begin); using (TextReader reader = new StreamReader(stream)) { // Registering currently iterated widget's HTML as an insertion on client side. AjaxPage.RegisterWidgetChanges(JsonClientID, "__p5_add_" + Controls.IndexOf(idx), reader.ReadToEnd()); } } } }
/// <summary> /// Initializes a new instance of the <see cref="StatePersister"/> class. /// </summary> /// <param name="page">Page instance</param> /// <param name="numberOfViewStateEntries">Number of view state entries per session</param> internal StatePersister(AjaxPage page, int numberOfViewStateEntries) : base(page) { _numberOfViewStateEntries = numberOfViewStateEntries; if (_numberOfViewStateEntries < 0 || _numberOfViewStateEntries > 50) { throw new ApplicationException("Legal value for '.p5.webapp.viewstate-per-session-entries' web.config setting is between 0 and 50"); } _viewStateId = page.IsPostBack ? new Guid(page.Request ["_p5_state_key"]) : Guid.NewGuid(); if (page.IsAjaxRequest) { return; } // Adding the viewstate ID to the form, such that we can retrieve it again when the client does a postback var literal = new LiteralControl { Text = string.Format("\t<input type=\"hidden\" value=\"{0}\" name=\"_p5_state_key\">\r\n\t\t", _viewStateId) }; if (page.Master != null) { // Need to add control to the first ContentPlaceholder that's inside of our main form. // Notice, if there are none, we default to the page's Form. var parent = FindFormControl(page.Master) ?? page.Form; parent.Controls.Add(literal); } else { page.Form.Controls.Add(literal); } }
/* * Renders all controls that was added this request. */ private void RenderAddedWidgets() { // Looping through all Controls, figuring out which were not there in the "_originalCollection", before it was changed, and retrieving their // HTML, such that we can pass it to the client, as a JSON insertion. for (var idxNo = 0; idxNo < Controls.Count; idxNo++) { var idx = Controls [idxNo]; if (_originalCollection.Contains(idx) || string.IsNullOrEmpty(idx.ID)) { continue; // Control has already been rendered, or is a literal control without an ID } // Getting control's HTML, by rendering it into a MemoryStream, and for then to pass it on as an "insertion" to our AjaxPage. using (var stream = new MemoryStream()) { using (var txt = new HtmlTextWriter(new StreamWriter(stream))) { idx.RenderControl(txt); txt.Flush(); } // Now we can read the HTML from our MemoryStream. stream.Seek(0, SeekOrigin.Begin); using (TextReader reader = new StreamReader(stream)) { // Registering currently iterated widget's HTML as an insertion on client side. AjaxPage.RegisterWidgetChanges(ClientID, "__p5_add_" + idxNo, reader.ReadToEnd()); } } } }
/* * Responsible for rendering all different permutations for a visible widget. */ void RenderVisibleWidget(HtmlTextWriter writer) { // How its ancestor Control(s) are being rendered, largely detremine how this widget is rendered, since an ancestor being shown, // that was previously hidden, or newly created for that matter, triggers a re-rendering of the entire widget, one way or another. if (!AjaxPage.IsAjaxRequest || AncestorIsReRendering()) { // Not an Ajax request, or ancestors are re-rendering widget somehow. // Hence, we default to rendering widget as HTML into the given HtmlTextWriter. RenderHtmlResponse(writer); } else if (RenderMode == RenderingMode.ReRender) { // Re-rendering entire widget, including its children. using (var streamWriter = new StreamWriter(new MemoryStream())) { using (var txt = new HtmlTextWriter(streamWriter)) { RenderHtmlResponse(txt); txt.Flush(); streamWriter.BaseStream.Seek(0, SeekOrigin.Begin); using (TextReader reader = new StreamReader(streamWriter.BaseStream)) { AjaxPage.RegisterWidgetChanges(JsonClientID, "outerHTML", reader.ReadToEnd()); } } } } else { // Only pass changes for this widget back to the client as JSON, before we render its children. Attributes.RegisterChanges(AjaxPage, JsonClientID); RenderChildren(writer); } }
public void p5_web_include_javascript_file(ApplicationContext context, ActiveEventArgs e) { // Looping through each JavaScript file supplied foreach (var idxFile in XUtil.Iterate <string> (context, e.Args)) { // Passing file to client AjaxPage.IncludeJavaScriptFile(context.RaiseEvent(".p5.io.unroll-path", new Node("", idxFile)).Get <string> (context)); } }
public void p5_web_send_javascript(ApplicationContext context, ActiveEventArgs e) { // Looping through each JavaScript snippet supplied foreach (var idxSnippet in XUtil.Iterate <string> (context, e.Args)) { // Passing JavaScript to client AjaxPage.SendJavaScript(idxSnippet); } }
public void p5_web_include_css_file(ApplicationContext context, ActiveEventArgs e) { // Looping through each stylesheet file supplied foreach (var idxFile in XUtil.Iterate <string> (context, e.Args)) { // Register file for inclusion back to client AjaxPage.IncludeCSSFile(context.RaiseEvent(".p5.io.unroll-path", new Node("", idxFile)).Get <string> (context)); } }
public static object CreateAdapter(ScriptEngine engine, IModelInstance instance, string propertyName) { AjaxPage page = new AjaxPage(); using (page.BeginContext(instance.Instance, null)) { Adapter realAdapter = (Adapter)Binding.Parse("", "{@ " + propertyName + "}").Evaluate(page).Value; return(realAdapter == null ? null : new AdapterWrapper(engine, realAdapter)); } }
/* * Renders all controls that was removed this request. */ void RenderDeletedWidgets() { // Iterates through all Controls that were removed during this request, and make sure we register them for deletion on client side. // Notice, we don't care about LiteralControls, which have empty IDs. var controls = Controls.Cast <Control> (); foreach (var idxControl in _originalCollection.Where(ix => !string.IsNullOrEmpty(ix.ID) && !controls.Any(ix2 => ix2 == ix))) { AjaxPage.RegisterDeletedWidget(idxControl.ClientID); } }
/// <summary> /// Initializes a new instance of the <see cref="PageManager"/> class /// </summary> /// <param name="context">Application Context</param> /// <param name="page">Ajax Page</param> public PageManager(ApplicationContext context, AjaxPage page) { // Setting Page for instance AjaxPage = page; // Initializing lambda and ajax event storage InitializeEventStorage(context); // Registers all event listeners RegisterListeners(context); }
/// <summary> /// Renders the widget. /// /// Overridden to entirely bypass the ASP.NET Web Forms rendering, and provide our own with Ajax support. /// </summary> /// <param name="writer">Writer.</param> public override void RenderControl(HtmlTextWriter writer) { if (AreAncestorsVisible()) { var ancestorReRendering = IsAncestorReRenderingThisWidget(); if (Visible) { if (AjaxPage.IsAjaxRequest && !ancestorReRendering) { if (RenderMode == RenderingMode.ReRender) { // Re-rendering entire widget. // Notice, since GetWidgetHtml will return HTML for widget, and its children controls, it's not necessary to invoke // "RenderChildren" or any similar methods here. AjaxPage.RegisterWidgetChanges(_oldId ?? ClientID, "outerHTML", GetWidgetHtml()); } else if (RenderMode == RenderingMode.ChildrenCollectionModified) { // Re-rendering all children controls, but also renders changes to widget. _attributes.RegisterChanges(AjaxPage, _oldId ?? ClientID); RenderChildrenWidgetsAsJson(writer); } else { // Only pass changes back to client as JSON. _attributes.RegisterChanges(AjaxPage, _oldId ?? ClientID); RenderChildren(writer); } } else { // Not an Ajax request, or ancestors are re-rendering widget somehow. RenderHtmlResponse(writer); } } else { // Invisible widget. if (AjaxPage.IsAjaxRequest && RenderMode == RenderingMode.RenderInvisible && !ancestorReRendering) { // Re-rendering widget's invisible markup. // Widget was probably made invisible during the current request. AjaxPage.RegisterWidgetChanges(_oldId ?? ClientID, "outerHTML", GetWidgetInvisibleHtml()); } else if (!AjaxPage.IsAjaxRequest || ancestorReRendering) { // Rendering invisible HTML. writer.Write(GetWidgetInvisibleHtml()); } } } }
public void p5_web_set_location(ApplicationContext context, ActiveEventArgs e) { // Checking if this is ajax callback, which means we'll have to redirect using JavaScript if (AjaxPage.IsAjaxRequest) { // Redirecting using JavaScript AjaxPage.SendJavaScript(string.Format("window.location='{0}';", XUtil.Single <string> (context, e.Args).Replace("'", "\\'"))); } else { // Redirecting using Response object AjaxPage.Response.Redirect(XUtil.Single <string> (context, e.Args)); } }
/// <summary> /// Initializes a new instance of the Filter class. /// </summary> /// <param name="page">The Ajax page this instance belongs to</param> protected Filter(AjaxPage page) { // Making sure our AjaxPage object stays around by reference, since it's needed at other places during filter's life cycle. Page = page; // Making sure we handle any unhandled exceptions, such that we can delete the filter, and render the default HTML back to client. Page.Error += Page_Error; // Making it possible to "chain" filters, adding additional filters. _next = Page.Response.Filter; // Keeping any existing content encoding, to make sure we support alternative encodings during rendering. ContentEncoding = Page.Response.ContentEncoding; }
/* * Responsible for rendering all different permutations for an invisible widget. */ void RenderInvisibleWidget(HtmlTextWriter writer) { var ancestorReRendering = AncestorIsReRendering(); if (AjaxPage.IsAjaxRequest && RenderMode == RenderingMode.WidgetBecameInvisible && !ancestorReRendering) { // Re-rendering widget's invisible markup, since widget was made invisible during the current request. AjaxPage.RegisterWidgetChanges( JsonClientID, "outerHTML", string.Format(@"<{0} id=""{1}"" style=""display:none important!;""></{0}>", Element, ClientID)); } else if (!AjaxPage.IsAjaxRequest || ancestorReRendering) { // Rendering invisible HTML. writer.Write(string.Format(@"<{0} id=""{1}"" style=""display:none important!;""></{0}>", Element, ClientID)); } }
public void p5_web_set_location(ApplicationContext context, ActiveEventArgs e) { // Checking if this is ajax callback, which means we'll have to redirect using JavaScript if (AjaxPage.IsAjaxRequest) { // Redirecting using JavaScript. AjaxPage.SendJavaScript(string.Format("window.location='{0}';", XUtil.Single <string> (context, e.Args).Replace("'", "\\'"))); } else { // Redirecting using Response object. try { AjaxPage.Response.Redirect(XUtil.Single <string> (context, e.Args)); } catch (System.Threading.ThreadAbortException) { ; // Silently catching, no reasons to allow it to penetrate ... } } }
/// <summary> /// Registers the changed attributes during this request. /// </summary> /// <param name="page">The Ajax page that owns the current instance</param> /// <param name="id">ID of widget that owns storage object</param> internal void RegisterChanges(AjaxPage page, string id) { // Adding up the ones that were deleted during this request. foreach (var idx in _dynamicallyRemovedThisRequest) { page.RegisterDeletedAttribute(id, idx.Name); } // Adding up our changes. foreach (var idx in _dynamicallyAddedThisRequest) { // Checking if this is an invisible attribute, at which case it is never rendered back to client. if (idx.Name.StartsWith("_", StringComparison.InvariantCulture) || idx.Name.StartsWith(".", StringComparison.InvariantCulture)) { continue; } // Registering change to be returned to client. page.RegisterWidgetChanges(id, idx.Name, idx.Value); } }
/// <summary> /// Initializes a new instance of the <see cref="StatePersister"/> class. /// </summary> /// <param name="page">Page instance</param> /// <param name="numberOfViewStateEntries">Number of view state entries per session</param> internal StatePersister(AjaxPage page, int numberOfViewStateEntries) : base(page) { _numberOfViewStateEntries = numberOfViewStateEntries; if (_numberOfViewStateEntries < 0 || _numberOfViewStateEntries > 50) { throw new ApplicationException("Legal value for '.p5.webapp.viewstate-per-session-entries' web.config setting is between 0 and 50"); } _viewStateId = page.IsPostBack ? new Guid(page.Request ["_p5_state_key"]) : Guid.NewGuid(); if (page.IsAjaxRequest) { return; } // Adding the viewstate ID to the form, such that we can retrieve it again when the client does a postback var literal = new LiteralControl { Text = string.Format("\t<input type=\"hidden\" value=\"{0}\" name=\"_p5_state_key\">\r\n\t\t", _viewStateId) }; page.Form.Controls.Add(literal); }
/// <summary> /// Initializes a new instance of the JsonFilter class. /// </summary> /// <param name="page">The AjaxPage this instance is rendering for</param> public JsonFilter(AjaxPage page) : base(page) { Page.Response.Headers ["Content-Type"] = "application/json"; }
/// <summary> /// Renders all children as JSON update(s) back to client. /// </summary> protected virtual void RenderChildrenWidgetsAsJson(HtmlTextWriter writer) { // re-rendering all children by default AjaxPage.RegisterWidgetChanges(ClientID, "innerValue", GetChildrenHtml()); }
public void p5_web_reload_location(ApplicationContext context, ActiveEventArgs e) { // Redirecting using JavaScript. AjaxPage.SendJavaScript("window.location.replace(window.location.href);"); }
public void p5_web_get_root_location(ApplicationContext context, ActiveEventArgs e) { // Making sure we clean up and remove all arguments passed in after execution using (new ArgsRemover(e.Args)) { // Returning web apps root URL e.Args.Value = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + AjaxPage.ResolveUrl("~/"); } }
/// <summary> /// Initializes a new instance of the HtmlFilter class. /// </summary> /// <param name="page">The AjaxPage this instance is rendering for</param> public HtmlFilter(AjaxPage page) : base(page) { }
/// <summary> /// Initializes a new instance of the HtmlFilter class. /// </summary> /// <param name="page">The AjaxPage this instance is rendering for</param> /// <param name="removeViewState">If true, all traces of ViewState will be removed from the page</param> public HtmlFilter(AjaxPage page, bool removeViewState) : base(page) { _removeViewState = removeViewState; }