Asp. NET's discovery and resolution of a bug

Source: Internet
Author: User
Tags button type iis net bug
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.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.