ControlAdapter.Browser 属性

定义

获取对发出当前 HTTP 请求的客户端的浏览器功能的引用。

protected:
 property System::Web::HttpBrowserCapabilities ^ Browser { System::Web::HttpBrowserCapabilities ^ get(); };
protected System.Web.HttpBrowserCapabilities Browser { get; }
member this.Browser : System.Web.HttpBrowserCapabilities
Protected ReadOnly Property Browser As HttpBrowserCapabilities

属性值

HttpBrowserCapabilities

一个 HttpBrowserCapabilities,指定客户端浏览器和标记功能。

示例

下面的代码示例演示如何使用 Browser 属性访问请求浏览器的详细信息。 在此示例中,代码会检查以确定浏览器是否与 JavaScript 兼容,然后允许开发人员在这种情况下呈现自定义输出。

#using <System.Web.dll>
#using <System.dll>

using namespace System;
using namespace System::Web::UI;
using namespace System::Web::UI::Adapters;

public ref class CustomControlAdapter: public ControlAdapter
{
protected:
   virtual void Render( HtmlTextWriter^ writer ) override
   {
      // Access Browser details through the Browser property.
      Version^ jScriptVersion = Browser->JScriptVersion;
      
      // Test if the browser supports Javascript.
      if ( jScriptVersion != nullptr )
      {
         // Render JavaScript-aware markup.
      }
      else
      {
         // Render scriptless markup.
      }
   }
};
using System;
using System.Web.UI;
using System.Web.UI.Adapters;

public class CustomControlAdapter : ControlAdapter
{
    protected override void Render( HtmlTextWriter writer )
    {
        // Access Browser details through the Browser property.
        Version jScriptVersion = Browser.JScriptVersion;

        // Test if the browser supports Javascript.
        if (jScriptVersion != null)
        {
            // Render JavaScript-aware markup.
        }
        else
        {
            // Render scriptless markup.
        }
    }
}
Imports System.Web.UI
Imports System.Web.UI.Adapters

Public Class CustomControlAdapter
    Inherits ControlAdapter

    Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

        ' Access Browser details through the Browser property.
        Dim jScriptVersion As Version = Browser.jScriptVersion

        ' Test if the browser supports Javascript.
        If Not (jScriptVersion Is Nothing) Then
            ' Render JavaScript-aware markup.
        Else
            ' Render scriptless markup.
        End If

    End Sub

End Class

注解

对象ControlAdapter从属性返回Browser的对象中确定客户端浏览器功能HttpBrowserCapabilities。 这使对象能够 ControlAdapter 呈现特定于浏览器的标记,或者修改浏览器 Control的行为。

适用于

另请参阅