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

Форма теста внешних действий #falconstart

Вызов внешних действий - это возможность действия, выходящего за рамки возможности работы с БД через…

2 месяца ago

Концепция внешних действий – telegram, email, уведомления на сайте

Вызов внешних действий - это возможность действия, выходящего за рамки возможности работы с БД через…

2 месяца ago

Работа с JSON в SQL #falconstart

После выполнения действий в SQL на клиенте иногда возникает необходимость что-то обновить или сделать. Для…

2 месяца ago

Форма с отправкой запроса API. Тестирование исходящих запросов #falconstart

Вы можете обратиться к внешним API через использование Внешних действий (код apirequest, использование описано в…

2 месяца ago

Таблица Trace для отслеживания событий на сайте

В системной таблице as_trace хранятся данные по работе приложения. Поле code определяет тип события: DBLREQ…

2 месяца ago

Работа с ошибками в системе. Генерация отчета по ошибкам #falconstart

Рассмотрим механизм анализа ошибок, как это всё работает, и как его использовать. Когда происходит ошибка…

2 месяца ago