如何获得当前的ASP。净HttpContext.Current主题曲吗?

时间:2022-08-13 07:30:17

I am using AJAX to load a user control from server side within an HTTP Handler. To do this, I am creating a new page object and executing the user control server side to generate raw HTML, like so:

我正在使用AJAX从服务器端加载HTTP处理程序中的用户控件。为此,我正在创建一个新的页面对象,并执行用户控制服务器端来生成原始HTML,如下所示:

   Dim page As New Page()
   Dim frm As New HtmlForm
   Dim commentTag As String = "CaptureText"
   Dim viewControl As UserControl = CType(page.LoadControl(VirtualPathUtility.ToAbsolute(String.Format("~/Help/{0}.ascx",Topic))), UserControl)
   page.Controls.Add(frm)
   frm.Controls.Add(New LiteralControl(String.Format("<!-- {0} -->", commentTag)))
   frm.Controls.Add(viewControl)
   frm.Controls.Add(New LiteralControl(String.Format("<!-- /{0} -->", commentTag)))

   Dim writer As New StringWriter()
   context.Server.Execute(page, writer, False)
   context.Response.ContentType = "text/html"
   context.Response.Write(GetContents(writer.ToString, commentTag))

GetContents() is simply a function that returns everything between the 2 hard-coded HTML comments, which is effectively only the HTML of my UserControl.

GetContents()只是一个函数,它返回两个硬编码的HTML注释之间的所有内容,实际上这只是我的UserControl的HTML。

The issue I am having is that some of these server controls require ASP.NET theme support. I found a way to do it by adding the following lines after the page declaration:

我的问题是,有些服务器控件需要ASP。净主题支持。我找到了一种方法,在页面声明之后添加以下几行:

   page.Theme = "Theme3"
   page.Controls.Add(New System.Web.UI.HtmlControls.HtmlHead())

This works like a charm when hard-coded with a theme name. However, I would like to get the theme name from the current context. All of the examples I have seen online require you to have a page object in order to get the name of the theme. But I am starting with a new page that has no theme.

这就像用主题名硬编码时的魅力。但是,我希望从当前上下文中获得主题名。我在网上看到的所有示例都要求您拥有一个page对象,以便获得主题的名称。但是我从一个没有主题的新页面开始。

So my question is whether there is a way to load the theme name from somewhere in HttpContext or is the only way to load this on the server side by passing the theme name from the client via AJAX?

所以我的问题是,是否有一种方法可以从HttpContext中加载主题名,还是只有通过AJAX从客户端传递主题名才能在服务器端加载?

1 个解决方案

#1


4  

(System.Web.HttpContext.Current.Handler as System.Web.UI.Page).Theme;

Or Assuming that you are using a default theme by specifying it in Pages section

或者假设您正在使用一个默认的主题,在Pages节中指定它

PagesSection pages = (PagesSection)WebConfigurationManager.GetSection("system.web/pages");

//use the them  via  pages.Theme

#1


4  

(System.Web.HttpContext.Current.Handler as System.Web.UI.Page).Theme;

Or Assuming that you are using a default theme by specifying it in Pages section

或者假设您正在使用一个默认的主题,在Pages节中指定它

PagesSection pages = (PagesSection)WebConfigurationManager.GetSection("system.web/pages");

//use the them  via  pages.Theme