OnCommand event on ImageButton control
<p>I have problem with OnCommand event. When I give this parametr as argument or display everything is all right, but if I used it as CommandArgument I get InvalidCastException. In code behind method CommandArgument is equal "" (string.Empty)</p>

<p>In my aspx file I have this code below:</p>

<pre><code>&lt;%# (bool)Eval("IsCandidateFavourite") %&gt; //just display value
&lt;asp:ImageButton id="ImageButton1" runat="server" 
    CommandArgument="&lt;%# (bool)Eval("IsCandidateFavourite") %&gt;"
    OnCommand="imBtnFavorite_Command"
    ImageUrl='&lt;%# GetIsFavoriteImageUrl((bool)(Eval("IsCandidateFavourite")) ) %&gt;'/&gt;
</code></pre>

<p>In my code behind file I have this</p>

<pre><code>public string GetIsCandidateFavoriteImageUrl(bool isNowFavorite)
{
    if (isNowFavorite)
    {
        return @"~/_images/icon_grid_fav.gif";
    }
    return @"~/_images/icon_grid_unfav.gif";
}

protected void imBtnFavorite_Command(object sender, CommandEventArgs e)
{
    bool isFavorite =(bool) e.CommandArgument;
}
</code></pre>
