ASP.Net/Request/Browser — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 11:53, 26 мая 2010

Assign value to browser title bar (C#)

<%@ Page Language="C#" %>
<script runat="server">
    void Page_Load()
    {
        ltlTitle.Text = DateTime.Now.ToString("D");
    }
</script>
<html>
<head>
    <title><asp:Literal id="ltlTitle" Runat="Server" /></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <h1>Look in the title bar</h1>
    
    </div>
    </form>
</body>
</html>



Browser name, major version and minor version (VB.net)

<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    Dim BCaps As HttpBrowserCapabilities
    BCaps = Request.Browser
    lblMessage.Text = "Browser Name: " _
        & BCaps.Browser & "<BR>" _
        & "Browser Major Version: " & BCaps.MajorVersion & "<BR>" _
        & "Browser Minor Version: " & BCaps.MinorVersion & "<BR>"
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Browser Type</TITLE>
</HEAD>
<form runat="server">
<asp:label 
    id="lblMessage" 
    font-size="12pt"
    font-name="Tahoma"
    runat="server"
/>
</form>
</BODY>
</HTML>



Check Browser version and name (VB.net)

<%@ Page Language="VB" %>
<script language="vb" runat="server">
  Sub Page_Load(Source As Object, E as EventArgs)
    If Not IsPostBack Then
      If Request.Browser.Browser = "IE" Then
         If Request.Browser.MajorVersion < 6 Then
           MyLabel.Text = "Time to upgrade Internet Explorer!"
        Else
          MyLabel.Text = "Your copy of Internet Explorer is up to date."
        End If
      Else
        MyLabel.Text = "You"re not using Internet Explorer"
      End If
    End If
  End Sub
</script>
<html>
  <body>
    <asp:Label id=MyLabel runat="server" Text=""/>
  </body>
</html>



Check Browser version and vendor(C#)

<%@ Page Language="c#" %>
<script Language="c#" runat="server">
  void Page_Load(object source, EventArgs e)
  {
    if (!(IsPostBack))
    {  
      if (Request.Browser.Browser == "IE")
      {
        if (Request.Browser.MajorVersion < 6)
        {
           MyLabel.Text = "Time to upgrade Internet Explorer!";
        }
        else
        {
          MyLabel.Text = "Your copy of Internet Explorer is up to date.";
        }
      }
      else
      {
        MyLabel.Text = "You"re not using Internet Explorer";
      }
    }
  }
</script>
<html>
  <body>
    <asp:Label id=MyLabel runat="server" Text=""/>
  </body>
</html>



Get Browser Information: AOL, JavaScript enabled, Browser type and tables enabled (VB.net)

<%@ Page Language="VB" %>
<script runat="server">
  sub Page_Load()
    lblRequestType.Text =   Request.RequestType
    lblAOL.Text =         Request.Browser.AOL
    lblJavaScript.Text =   Request.Browser.JavaScript
    lblBrowserType.Text =   Request.Browser.Type
    lblTableSupport.Text =   Request.Browser.Tables
  end sub
</script>
<html>
  <body>
    Request type : <asp:label id=lblRequestType runat="server" /><br />
    AOL : <asp:label id=lblAOL runat="server" /><br />
    JavaScript : <asp:label id=lblJavaScript runat="server" /><br />
    Browser : <asp:label id=lblBrowserType runat="server" /><br />
    Tables : <asp:label id=lblTableSupport runat="server" />
  </body>
</html>



Is your browser a beta one (VB.net)

<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    Dim BCaps As HttpBrowserCapabilities
    BCaps = Request.Browser
    If BCaps.Beta Then
        lblMessage.Text = "You are using a Beta browser!"
    Else
        lblMessage.Text = "You are not using a Beta browser!"
    End If
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Browser Beta</TITLE>
</HEAD>
<form runat="server">
<asp:label 
    id="lblMessage" 
    font-size="12pt"
    font-name="Tahoma"
    runat="server"
/>
</form>
</BODY>
</HTML>



Request.Browser.ActiveXControls: client supports activex? (VB.net)

<%@ Page Language="vb" %>
<html>
   <head>
      <title>ClientTarget property example</title>
      <script runat="server">
         Sub Page_Load()
            Page.ClientTarget = "downlevel"
            Message.Text = "Page is set to render for the " & _
               Page.ClientTarget & " alias.<br/>"
            Message.Text &= "Supported features:<br/>"
            Message.Text &= " - JavaScript: " & _
               Request.Browser.JavaScript & "<br/>"
            Message.Text &= " - ActiveX Controls: " & _
               Request.Browser.ActiveXControls & "<br/>"
            Message.Text &= " - Frames: " & _
               Request.Browser.Frames & "<br/>"
         End Sub
      </script>
   </head>
<body>
   <asp:label id="Message" runat="server"/>
</body>
</html>



Request.Browser.Frames: browser supports frames (VB.net)

<%@ Page Language="vb" %>
<html>
   <head>
      <title>ClientTarget property example</title>
      <script runat="server">
         Sub Page_Load()
            Page.ClientTarget = "downlevel"
            Message.Text = "Page is set to render for the " & _
               Page.ClientTarget & " alias.<br/>"
            Message.Text &= "Supported features:<br/>"
            Message.Text &= " - JavaScript: " & _
               Request.Browser.JavaScript & "<br/>"
            Message.Text &= " - ActiveX Controls: " & _
               Request.Browser.ActiveXControls & "<br/>"
            Message.Text &= " - Frames: " & _
               Request.Browser.Frames & "<br/>"
         End Sub
      </script>
   </head>
<body>
   <asp:label id="Message" runat="server"/>
</body>
</html>



Use Browser property in Request object (C#)

<%@Page Language="C#"%>
<html>
<body>
<form runat="server">
<asp:linkButton id="lnkTest" runat="server"
               forecolor="red"
               backcolor="yellow"
               width="50%"
               font-name="Times New Roman,serif"
               font-size="larger"
               font-bold="true"
               text="a yellow link button with red text" />
</form>
<br />
JavaScript supported: <% = Request.Browser["javascript"] %><br />
Reported type: <% = Request.Browser["type"] %>
</body>
</html>