让黑莓blackberry的浏览器支持asp.net的回发机制postback

<script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

 

Introduction

While writing ASP.NET applications targeting the BlackBerry browser I have made some interesting discoveries. In this article I will show how to configure .NET 2.0 to recognise the BlackBerry browser so that it behaves as you would expect.

Background

I have developed several ASP.NET 1.1 applications targeting the BlackBerry browser version 4.1 on the 7290 device and more recently the 8700g. I have been upgrading those projects to ASP.NET 2.0 and was quite baffled initially, when several features would just not work.

Creating a BlackBerry.browser config file

After a quick look through the /WINDOWS/Microsoft.NET/Framework/v2.0.50727/CONFIG/Browsers directory I discovered that version 2.0 of the framework does not ship with configuration details for the BlackBerry browser. Some of the older browsers are covered with the goAmerica.browser configuration file but that doesn't cover the newer browsers.

To find out what the framework knows about a browser you can create a page which writes out some details:

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("<B>User Agent:</B> " + Request.UserAgent + "<BR />");
    Response.Write("<B>IsMobileDevice:</B> " + Request.Browser.IsMobileDevice
    + "<BR />");
    Response.Write("<B>Browser:</B> " + Request.Browser.Browser + "<BR />");
    Response.Write("<B>Version:</B> " + Request.Browser.Version + "<BR />");
    Response.Write("<B>Major:</B> " + Request.Browser.MajorVersion + "<BR />");
    Response.Write("<B>Minor:</B> " + Request.Browser.MinorVersion + "<BR />");
}

Browsing to this page on a Blackberry the UserAgent will return something like this:
   BlackBerry8700/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/-1
This is useful information but Browser name and version information are not returned.

Creating a Blackberry.browser config file is pretty straight forward. Having a read through the other *.browser files will give you an idea of what properties can be set. Here is the configuration which I have created:

 

<browsers>

  <browser id="BlackBerry" parentID="Default">
    <identification>
      <userAgent match="BlackBerry(?'model'/d+)/(?'version'((?'major'/d+).
(?'minor'/d+).(?'other'/d+)))" />
    </identification>

    <capabilities>
      <capability name="browser"             value="BlackBerry" />
      <capability name="isMobileDevice"      value="true" />
      <capability name="javascript"          value="true" />
      <capability name="ecmascriptversion"   value="1.3" />          
      <capability name="version"             value="${version}" />
      <capability name="majorVersion"        value="${major}" />
      <capability name="minorVersion"        value="${minor}" />
      <capability name="supportsCss"         value="true" />
      <capability name="frames"              value="false" />
      <capability name="cookies"             value="true" />
    </capabilities>
  </browser>
  
</browsers>

In the browser tag we just set the id and parentID attributes. In the identification tag we create a regular expression to capture a match on the userAgent we looked at earlier. Under capabilities we set the various properties for the browser.

One of the most important capabilities here is the ecmascriptversion. It lets the framework know that its ok to write out the __doPostBack javascript method and the __EVENTTARGET & __EVENTARGUMENT hidden fields. These are used by events such as the SelectedIndexChanged on a DropDownList control.

There are many other properties which can be set but I have found these sufficient for my needs. Enter these details in a text file and save as BlackBerry.browser in the C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/CONFIG/Browsers directory.

ASP.NET Browser Registration Tool

Creating the file is only half the job. We now need to let the framework know about it. There is a command line tool called aspnet_regbrowsers.exe which creates an assembly based on the information in the *.browser files and installs the assembly in the global assemly cache.

From a command prompt enter the path to aspnet_regbrowsers.exe and use the -i switch to register the browser configurations. For my installation the path is as follows:
   C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/aspnet_regbrowsers.exe -i
Just check that this is the correct location for your installation.

More information on aspnet_regbrowsers.exe can be found here.

Conclusion

The ecmascriptversion can be an important property for the framework to know about a browser. The applications I have upgraded from ASP.NET 1.1 to 2.0 now behave as they should on the BlackBerry browser.

-------------------------------------------------------------------------------------------------------------------------------

以上文章是从codeproject上转过来的,经过我试验,根据上面说的配置以后还是不能实现dropdownlist的indexchange事件的回发,我再web.config配置文件的system.web节中加入如下配置,一切都OK了。

<browserCaps>
      <filter><case match="(BlackBerry)+.">EcmaScriptVersion = 1.5</case>
      </filter>
    </browserCaps>

如果你不想更改web.config文件,还有一个方法:

在dropdwonlist里面加入"AutoPostBack=true", type "οnchange=formname.submit();" formname是dropdownlist所在form的名字(name),这样也可以实现他的indexchange回发事件。

 

不过还是推荐大家用第一种方法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值