Far Away Developer

Sebastien Lachance

Archive for December, 2006

Visual C# Code Snippet collection

Posted by Sebastien Lachance on December 14, 2006

If you are using Visual Studio 2005 and C#, you should try the free C# Code Snippet collection from MSDN. I’m using it since the release (I know, I’m sorry, I should have you let it know sooner) and found them rather useful.

Posted in .NET, Visual Studio | No Comments »

CommandField and ButtonType="Image"

Posted by Sebastien Lachance on December 1, 2006

My first real bug with the framework and a good one. It appears that if you have a CommandField in a GridView with the ButtonType set to Image with an ImageUrl for the button you want, the event (OnRowDeleting, OnRowEditing, etc..) will be fired twice. But the DataSource could play some part in it. By example, if you have an SqlDataSource, it will not happen. In my case, it was a list of object bound in the codebehind.

The way I found to resolve this issue was to create a TemplateField and add an ImageButton with a CommandName of “Delete”. This way the OnRowDeleting will be fired (for a list of other command name, just fire the OnRowCommand event and check what the GridViewCommandEventArgs.CommandName). I’m still trying to find an official response from the .NET team to confirm all this, but the community think it’s a bug.

If you do not want to create a TemplateField for this, there is an alternate solution. You can use this in you event :

if (Request["x"] == null || Request["y"] == null)
{
Response.End();
}

Posted in .NET, ASP.NET | No Comments »