03 May 2008

A bug in ASP.Net 2.0 Gridview control and ...

I don’t know why it has to be like this! I know BUG is a non-detachable part of software development and according to a Murphy’s law: "Each computer code has five bugs, and this number does not depend on how many bugs have been already found." (!?)

But, when a bug was found and reported to a company like Microsoft, why it should take so long to fix it? And isn't it better if Microsoft add a note or comment in MSDN like: "this is a known bug and here is the workaround..." so that people don't get confused by getting a different result from a sample code? Or maybe Bill Gates wants to make developers more creative?!

To make the long story short, last week after several frustrating hours debugging a Gridview image button which was firing an command event twice, I found it's a known bug in ASP.Net 2.0 and was reported to Microsoft on 2006, and yet to be fixed! The funny thing is it works fine when you have a LinkButton instead of ImageButton.

I finally found a workaround for this:

Put your imagebutton in an ItemTemplate and add:

The rest is same as other Gridview commands, you need to write your code in RowCommand event of the Gridview and find the index of the row like this:

Dim index As Integer = Convert.ToInt32(e.CommandArgument) Dim myRow As GridViewRow = CartGrid.Rows(index) If (e.CommandName = "YourCommandName") Then ....

Have a look at this page, (a frustrated developer was trying to get help about this issue and answer of Microsoft Online Support...):

http://www.netnewsgroups.net/group/microsoft.public.dotnet.framework.aspnet/topic16694.aspx

No comments:

Post a Comment