コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctr"></param>
        /// <returns></returns>
        public static ControlRenderMode GetControlRenderMode(Control ctr)
        {
            PageRenderMode    pageRenderMode = WebUtility.GetRequestPageRenderMode();
            ControlRenderMode renderMode     = new ControlRenderMode(pageRenderMode);

            PageRenderModePageCache currentPageCache = PageRenderModeHelper.GetPageRenderModeCache(ctr.Page);
            PageRenderModePageCache requestPageCache = renderMode.PageCache;

            int    currentPageLevel    = GetPageLevel(currentPageCache);
            string currentPageUniqueID = GetPageUniqueID(currentPageCache);
            int    requestPageLevel    = GetPageLevel(requestPageCache);
            string requestPageUniqueID = GetPageUniqueID(requestPageCache);

            if (requestPageLevel == currentPageLevel)
            {
                if (ctr.UniqueID == pageRenderMode.RenderControlUniqueID)
                {
                    renderMode.OnlyRenderSelf = true;
                }
            }
            else if (requestPageLevel > currentPageLevel)
            {
                string id = requestPageUniqueID.Split(',')[currentPageLevel];

                if (ctr.UniqueID == id)
                {
                    renderMode.OnlyRenderSelf = true;
                }
            }

            return(renderMode);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctr"></param>
        /// <param name="renderMode"></param>
        public static void CheckOnlyRenderSelf(Control ctr, ControlRenderMode renderMode)
        {
            if (renderMode.OnlyRenderSelf && renderMode.UseNewPage && ctr.Page.Items[WebUtility.PageRenderControlItemKey] != ctr)
            {
                Page currentPage = ctr.Page;
                ctr.Parent.Controls.GetType().GetMethod("SetCollectionReadOnly", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(ctr.Parent.Controls, new object[1] {
                    null
                });
                Page page = new Page();
                PageRenderModePageCache currentPageCache = PageRenderModeHelper.GetPageRenderModeCache(currentPage);
                PageRenderModePageCache pageCache        = PageRenderModeHelper.GetPageRenderModeCache(page);
                SetPageLevel(pageCache, GetPageLevel(currentPageCache) + 1);
                string currentPageUniqueID = GetPageUniqueID(currentPageCache);
                if (currentPageUniqueID != string.Empty)
                {
                    currentPageUniqueID += ",";
                }
                SetPageUniqueID(pageCache, string.Format("{0}{1}", GetPageUniqueID(currentPageCache), ctr.UniqueID));
                page.AppRelativeVirtualPath = ctr.Page.AppRelativeVirtualPath;
                page.EnableEventValidation  = false;

                InitNewPageContent(page, ctr);

                WebUtility.AttachPageModules(page);

                page.ProcessRequest(HttpContext.Current);

                HttpContext.Current.Response.End();
            }
        }
コード例 #3
0
        /// <summary>
        /// 根据控件输出模式,输出控件
        /// </summary>
        /// <param name="ctr">要输出的控件</param>
        /// <param name="baseRenderString">控件原输出内容</param>
        /// <param name="renderMode">输出模式</param>
        /// <remarks>根据控件输出模式,输出控件</remarks>
        internal static void RenderControlOnlySelf(Control ctr, string baseRenderString, ControlRenderMode renderMode)
        {
            HttpResponse response = HttpContext.Current.Response;

            response.ClearContent();
            response.ContentEncoding = Encoding.UTF8;
            response.Charset         = "utf-8";

            string htmlContentType = WebUtility.GetContentTypeByKey(ResponseContentTypeKey.HTML);
            string contentType     = WebUtility.GetContentTypeByKey(renderMode.ContentTypeKey);

            if (contentType == string.Empty)
            {
                contentType = htmlContentType;
            }

            response.ContentType = contentType;

            string renderStr = contentType == htmlContentType?
                               GetRenderSingleControlString(ctr, baseRenderString) :
                                   GetFileRenderSingleControlString(baseRenderString, contentType);

            switch (renderMode.DispositionType)
            {
            case ResponseDispositionType.Inline:
            case ResponseDispositionType.Attachment:
                response.AppendHeader("CONTENT-DISPOSITION",
                                      string.Format("{0};filename={1}", renderMode.DispositionType, HttpUtility.UrlEncode(renderMode.AttachmentFileName)));
                break;
            }

            response.Write(renderStr);
            response.End();
        }