locked
PreferredRenderingMIME RRS feed

  • Question

  • User-1266225229 posted

     Hi Forum, im trying to detect wml against html using PreferredRenderingMIME script. I sourced this from MSDN but cant debug this error.

    CS0246: The type or namespace name 'MobileCapabilities' could not be found. REALLY appreciate some good advice thanks Paul

     

    <%@ Page Inherits="System.Web.UI.MobileControls.MobilePage"
       Language="c#" %>

    <script language="c#" runat="server">

    public void Page_Load(Object sender, EventArgs e)
    {

       System.Web.Mobile.MobileCapabilities currentCapabilities;

       MobileCapabilities currentCapabilities =
          (MobileCapabilities)Request.Browser;

       // Programatically find the mobile capabilities without using
       // DeviceSpecific Filters.
       if(currentCapabilities.PreferredRenderingMIME=="text/html")
       {
          Label2.Text = "You are using an html supported device.";
       }
       else if(currentCapabilities.PreferredRenderingMIME=="text/vnd.wap.wml")
       {
          Label2.Text = "You are using a wml supported device.";
       }
       Label1.Text = "Screen Width (chars): " +
          currentCapabilities.ScreenCharactersWidth;
    }
    </script>

    <Mobile:Form runat="server" id=frmTemplate >
            <mobile:label ID="Label1" runat="server" />
            <mobile:label ID="Label2" runat="server" />
    </Mobile:Form>

    Thursday, March 15, 2007 1:11 AM

All replies

  • User-1179442337 posted

    hi there im not sure how you do this from how your doing it, i usually use code-behind pages for classes.

    but i think what you need is a using directive to access that class.

    using System.Web.Mobile;

     

    Thursday, March 15, 2007 3:12 AM
  • User-1266225229 posted

    jamsweb thanks for your reply!

    Ive added <%@ Import Namespace="System.Web.Mobile" %>

    returning this error now, can you help? P

    CS0128: A local variable named 'currentCapabilities' is already defined in this scope

      

    System.Web.Mobile.MobileCapabilities currentCapabilities;

       MobileCapabilities currentCapabilities =
          (MobileCapabilities)Request.Browser; 

    Thursday, March 15, 2007 6:42 AM
  • User-1179442337 posted

    i found a piece of code that is similiar, from msdn. i added in the labels and the screen width to this code.  it seems to work fine in both IE and a mobile browser.

    hope this works for you, here is the full page:

     

    <%@ Page Language="C#" Inherits="System.Web.UI.MobileControls.MobilePage" %>

    <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>

    <%@ Import Namespace="System.Web.Mobile" %>

    <script runat="server">

    public void Page_Load(Object sender, EventArgs e)

    {

    MobileCapabilities currentCapabilities

    = (MobileCapabilities)Request.Browser;

    String prefMime = currentCapabilities.PreferredRenderingMime;

    if (prefMime == "text/html")

    {

    Label2.Text = "Html supported browser";

     

    }

    else if (prefMime == "text/vnd.wap.wml")

    {

    Label2.Text = "Wml1.1 Supported browser";

    }

    Label1.Text = "Screen Width (chars): " + currentCapabilities.ScreenCharactersWidth;

    }

    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <body>

    <mobile:form id="form1" runat="server">

    <mobile:Label ID="Label1" Runat="server">Label</mobile:Label>

    <mobile:Label ID="Label2" Runat="server">Label</mobile:Label>

    </mobile:form>

    </body>

    </html>

    Thursday, March 15, 2007 3:19 PM
  • User-1266225229 posted
    Thanks again jamsweb, This now allows me to test mime types, i want to filter mobile xhtml devices from wml11 but have had trouble with preferredrendertype. so thought to try this way. If you have any further advice im listening! cheers Paul
    Thursday, March 15, 2007 9:59 PM