Asp.net| Solution
The type of the button in the GridView is executed two times when the Rowcommand event is triggered by using image, which is said to appear only in Ie6,ie5, Firefox, and so on, my IE7 also has the same problem, seems to have something to do with the IIS version, look forward to Microsoft's patch.
This afternoon, a problem encountered, the GridView Rowcommand event will be executed two times, postback will also perform two times, initially suspected to be a debugger problem, after looking at the log, determined to really be executed two times.
Code check n times, step out, still did not find the problem, has begun to suspect that the mouse, grab bag found is indeed sent two requests, and the first request has not been processed. Occasionally buttontype from image to button, the unexpected good, only executed once, it seems that the problem only out in ImageButton.
Through Google search found that a lot of people have encountered this problem, determined to be a asp.net bug. Click the button will send two requests to IIS, the first time is eight bytes less than the second, resulting in unsuccessful first request, and then will be sent again, so the most easy to think of is to ignore the first request, the following is the first solution.
There are currently two solutions that are imperfect, and the first is to add the following statement to the Rowcommand event:
if (request["x"] = = null && request["y"] = = null)
Response.End ();
This statement, which determines the coordinates of the picture, if its coordinates are NULL, is the first request because the first request is invalid and ends him.
The second is recommended by Microsoft: Try not to use ImageButton in the GridView, but link or button if you have to use a similar code:
<asp:gridview id= "GridView1" runat= "Server" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:imagebutton runat=server id= "ImageButton1" commandname= "Delete"
Imageurl= "" Commandargument= ' <%# DataBinder.Eval (Container,
"RowIndex")%> ' oncommand= ' Imagebutton1_command '/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void Imagebutton1_command (object sender, CommandEventArgs e) {
Gridview1.deleterow (Int32.Parse (e.commandargument.tostring ()));
}
Add Imagebuttong to the TemplateField and call DeleteRow in the event.
I don't know if there is a better solution, and the following forum discusses the problem in detail:
Http://www.developersdex.com/asp/message.asp?p=1116&r=4641456&page= 2 The result of the first page discussion is that this problem will only occur if the button type is image, and you can skip it, and the next two pages are discussed and resolved in detail.
Today, a day has been encountered strange problems, the first big, the same code often can be executed for a while, VS2005 also has been a strange thing. Just put the afternoon can not run a few problems at home to simulate a run well!! Tomorrow's going to be a headache.