Imitate UIPickerView behavior on safari

When the user encounter a drop-down box while browsing the web the safari loads a UIPicker view in order to populate the selections and present it to the user.
On one of my resent projects I needed this same functionality but implemented as a native solution and not as web-view/html solution.
The solution I found was using the UIActionSheet control that contains a UIPickerView as a subview.

In the .h file include:

UIActionSheet * pickerContainer;
UIPickerView * pickerItems;

In the .m file include this code on the viewDidLoad method:

pickerContainer = [[UIActionSheet alloc] init];
pickerItems = [[UIPickerView alloc] initWithFrame:CGRectMake(0,0,0,0)];
pickerItems.delegate = self;
[pickerContainer addSubview:pickerItems];

And when you want the picker to appear on screen execute this code:

[pickerContainer showInView:self.view];
[pickerContainer setBounds:CGRectMake(0,0,320,400)];

This will make the ActionSheet appear on screen in the same way the picker appears when you select a drop-down element on an HTML page.
You can also add buttons above the UIPickerView in order to mimic the same functionality that happens on web views.

Happy coding!

Netanel Lev

Facebook streamPublish cross-scripting error on IE8

For the past week I’ve worked on a big internet campaign that included an website where the users could connect to facebook using facebook connect and publish content from the site to their profile wall.
When I tried to publish the post on facebook I encountered an error I haven’t seen before and this error occurred only in Internet Explorer 8 , non of the other browsers (chrome, ff etc) produced this error  and the content didn’t appear in the publish box.
The was the error:
“ Internet explorer has modified this page to help prevent cross-site scripting “

PublishError

After googeling didn’t give me the answer I tried to modify the content I pass facebook on the FB.Connect.streamPublish function and I discovered that the parameter of the user_text has a limitation of 95 non English characters (my text was in Hebrew) cutting the text to less then the limitation fixed the issue!

Hope this helps,

Netanel Lev

Twitter is my radio station, Google Reader is my disc player!

TWvsGR

I don't have a single CD in my car (nor an MP3 player for that matter), my wife has about a dozen of CD's that she listen to all the time and she always ask me how can I drive without music? Well, I can't, but I love to listen to the music that is played from the radio and not from a CD.

You are probably thinking what the heck I'm talking about?! and what CD's or radio stations have to twitter or Google Reader?! So, let me explain.

Think about it like this, when you listen to the music from the radio you don't really know which song will be played next and if you will like it or not. The anticipation for the next song make the music in the radio somewhat more interesting and not predictable. In the other side when you listen to your favorite CD's or MP3's you basically know which type of songs you will hear and for me this is less interesting.

Twitter is not predictable, when I wrote these lines I followed around 223 people that are divided to 3-4 groups and have another 3 search columns on various topics on my TweetDeck(grate twitter client!). Every new tweet is a song that maybe I like or not but it's not predictable. On my Google Reader I read about 20 blogs on different topics but all my blogs are predictable, I know what to anticipate, I generally know which type of information I will get from those RSS feeds and sometimes it's just plain boring.

In the last couple of weeks I started to use twitter on a regular basics and found a whole new world of information, information that until know you needed to look for but twitter let you get the information right to your hands, all you need to do is just pay attention and read! Twitter is an huge information index and all you need to do is just know what you are looking for, someone probably already tweet it. I guess twitter will never replace my Google Reader completely because I love my blogs but twitter sure took the first place in the competition on my attention and because we are just humans and we have limited time to spend every day, my GR is now at the second place. I think that every time I'm in the mood to "hear a familiar song" I'll go back to my good old Google Reader.

What about you?
Did twitter replaced you disc player?

follow me on twitter @lnetanel
Netanel Lev

Want a better IE performance? Kill it's addons!

The other day I visited a friend of mine that bought a new netbook.
After installing windows XP SP3 and IE8 his browser perfomace dropped, web sites were loaded slowly and it took the IE ages to load.
At first he thought it was a malawere of some kind so he installed an antivirus and scanned the computer but the scan showed nothing.
After a little more research he said to me "I think I know who is the virus - the IE itself..." and guess what, he was right.
IE8 comes with a lot of addons that suppose to make your social life easier. I for one would never understand what is the use for those addons and don't know anyone that use them...
Apperentally those addons slow down the performance of the browser and as a result it take ages to make it launch or load websites.
As I see it if you want a better browsing experiance you have two options:
1. Disable those addons.
2. Use another browser.
Personally I'm a big fan of Google Chrome and use it as my default browser but because I'm a web developer who develop using .Net and Visual Studio technologies I can't just get rid of the IE.
The only choice I had left is to disable those addons and that exactly what I did.
Here is how you do it:
1. Go to Tools -> Manage add-ons
2. On the left side of the window that was opened choose "all add-ons"
3. Disable irrelevant add-ons by choosing them and press the disable button at the right bottom side of the window.
Now I don't need to be afraid that my pc will freeze every time I click on a link in an email message.
Hope this helps you too!
Netaenl

Developing an IPhone app with C#

Yes, it's possible.
A couple of days ago my friend Erez Eden sent me an email with a link to the Mono project web site.
For those of you that aren't familiar with it, mono is a "cross platform, open source .NET development framework" sponsored by Novell and the open source community - that means that you can develop applications to OS's other then Windows using .Net technology.
I'm familiar with this project for some time now but what I didn't know is that there is an IPhone OS version of the framework! that means that you can develop IPhone app using C# - How cool is that?
The subproject is called MonoTouch and you can find it here.
Currently it's not open to the public but hopefully it will be in this September.
The down side is that because the IPhone OS doesn't support JIT engines the code you write will be compiled to static native code for the OS.
That generally means no reflection and some more limitations for the development.
As a developer in the mobile industry that is a big fan of the .Net technology and espacially C# I was very excited to here about this framework but after I realised I'll still have to develop the application on a mac inorder to test it I started thinking why to bother and start to develop an application that rely on a third party framework, maybe it's better to suck it up and learn the Objective-C syntax and that's it (objective-c is the language that being used do develop applications to the IPhone and Mac) ....
I still don't know if I'll go with the mono or objective-c path but I'll sure give the MonoTouch a try once I'll get my hands on it!

What do you think?

Getting values of CheckBoxList items from javascript

On my last post I wrote on getting CheckBox values from client side.
On the same project I needed the same functionality for the CheckBoxList control. Because CheckBoxList hold ListItem I couldn't access the InputAtributes property of the CheckBox.
After some googling I found this post by Evan Freeman that explains how to create a new custom control that renders the server side values into the html code.
In this way you gain server side and client side functionality on the same time.
This is the code for the new ChcekBoxList control:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;
using System.Security.Permissions;

namespace System.Web.UI.WebControls{
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.LinkDemand,
Level = AspNetHostingPermissionLevel.Minimal),
ToolboxData("<{0}:WorkingCheckBoxList runat=\"server\" />")]
public class CheckBoxListWithClientValues : CheckBoxList
{
private CheckBox _controlToRepeat;
private bool _cachedIsEnabled;
private bool _cachedRegisterEnabled;

public CheckBoxListWithClientValues()
{
    this._controlToRepeat = new CheckBox();
    this._controlToRepeat.EnableViewState = false;
    this._controlToRepeat.ID = "0";
    this.Controls.Add(this._controlToRepeat);
}         

protected override void RenderItem(ListItemType itemType,
    int repeatIndex,
    RepeatInfo repeatInfo,
    System.Web.UI.HtmlTextWriter writer)
{   
    if (repeatIndex == 0)
    {     
        this._cachedIsEnabled = base.IsEnabled;
        this._cachedRegisterEnabled = ((this.Page != null) && base.IsEnabled);
    }               

    ListItem item = this.Items[repeatIndex];
    this._controlToRepeat.Attributes.Clear();

    if (item.Attributes.Count > 0) //has attributes  
    {       
        foreach (string str in item.Attributes.Keys)
        {          
            this._controlToRepeat.Attributes[str] = item.Attributes[str];
        } 
    }
    this._controlToRepeat.ID = repeatIndex.ToString(NumberFormatInfo.InvariantInfo);
    this._controlToRepeat.Text = item.Text;  
    this._controlToRepeat.Checked = item.Selected;
    this._controlToRepeat.EnableViewState = true;
    this._controlToRepeat.Enabled = this._cachedIsEnabled && item.Enabled;
    this._controlToRepeat.InputAttributes.Add("value", item.Value); //add the value attribute to be rendered
    this._controlToRepeat.RenderControl(writer);
}
}
}
And thanks for Evan for posting this code.
Happy coding.
Netanel.

ASP.NET Get a CheckBox value from javascript

Recently I needed to access the value of a CheckBox from javascript.
Because CheckBox doesn't have a Value property I tried the following:
myCheckBox.Attributed.Add("value", "test");
And tried to access it from javacstipt:
alert($("myCheckBox").value)
I was surprised to find out that the message in the alert was "on" and not "test" as I expected so I looked at the source of the page and this is what I saw:

As you can see the value I set on the server side code doesn't appear in the result html code.
After a little more research I found out there is a property for the CheckBox that is called "InputAttributes" - this property adds the attributes to the CheckBox input.
This is the correct code:
myCheckBox.InputAttributes.Add("value", "test");
That's all I needed.
Happy coding.
Netanel