Your best bet is to go with a UA detection script/library. One I found for ASP is here:
http://mobiforge.com/developing/story/lightweight-device-detection-asp
If the script does not offer the flexibility you want or is too complex for your needs, Request.ServerVariables("HTTP_USER_AGENT")
will return a user agent string that looks like this:
BlackBerry9000/4.6.0.167 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/102
In my experience, all BlackBerry browsers include "BlackBerry" in the UA string, and all iPhones include "iPhone" in the UA string, so you can run simple string manipulation on that. I'm a PHP man, so I can't help you write something off the top of my head, but if you need a sample code, post a comment and I or someone will get one out to you.