Categories: ASP.NET

Использование Delete в GridView и UpdatePanel

Решение:

SOLUTION FOUND IN AN OTHER DISCUSSION :

Well, this is a known issue when you are using ButtonType of “Image” for the commandField to post the page twice.

<asp:CommandField ButtonType="Image" DeleteImageUrl="http://tango.freedesktop.org/static/cvs/tango-icon-theme/16x16/places/user-trash.png"
ShowDeleteButton="True" />

Using ButtonType="Link" will solve your problem.

Well, the reason for this is, of the three button types (Button, Image, Link) for the CommandField, the first two (Button and Image) are of “input” type (Button input, type = submit) , (Image input, type=submit) and the Link is anchor tag.

Both of the input controls will automatically cause the form that they reside within to be posted back to the server when they are clicked, whereas the anchor will not – instead it needs some javascript to cause a postback. This is where the problem is – all three html controls are rendered out with javascript attached to post the form back to the server on a click event, which allows buttons of type ‘Link’ to work correctly but causes buttons of type ‘Button’ and ‘Image’ to postback twice – the first time due to the javascript and the second because of the native postback.

My workaround for this problem is to use a TemplateField

<asp:TemplateField >
<ItemTemplate>
<asp:ImageButton id="DeleteButton" CommandName="Delete" ImageUrl="~/images/delete.ico" runat="server" />
</ItemTemplate>
</asp:TemplateField>

 

Руслан Раянов

Recent Posts

Что нужно убрать?

http://falcon.web-automation.ru/ - платформа создания бизнес-приложений в виде личных кабинетов

3 дня ago

В гору или под гору

http://falcon.web-automation.ru/ - платформа создания бизнес-приложений в виде личных кабинетов

6 дней ago

Опросы клиентов – ключевой инструмент для бизнеса

http://falcon.web-automation.ru/ - платформа создания бизнес-приложений в виде личных кабинетов

1 неделя ago

Вежливость – бесплатный способ увеличить показатели бизнеса

http://falcon.web-automation.ru/ - платформа создания бизнес-приложений в виде личных кабинетов

2 недели ago

Проблема дисбаланса производства и продаж в сфере услуг

В статье разберем распространенную проблему в сфере услуг: либо слишком мало продаж, либо слишком много.…

2 недели ago

Бекап не нужен, когда все хорошо

http://falcon.web-automation.ru/ - платформа создания бизнес-приложений в виде личных кабинетов

2 недели ago