开发者

Custom validation not working with delete buttons?

开发者 https://www.devze.com 2023-01-19 08:44 出处:网络
In a ListView, I have a CustomValidator set up to validate a field whenever a button with CommandName=\"Delete\" is clicked.

In a ListView, I have a CustomValidator set up to validate a field whenever a button with CommandName="Delete" is clicked.

<ItemTemplate>
    <asp:TextBox ID="NameTextBox" Text=<%# Eval("Name") %> runat="server" />
    <asp:Button ID="DeleteButton" Text="Delete" CommandName="Delete" ValidationGroup="Delete" runat="server" />
    <asp:CustomValidator ValidationGroup="Delete" SetFocusOnError="true" Display="Dynamic" OnServerValidate="CustomValidator_ServerValidate" runat="server">You can't delete this.</asp:CustomValidator>
</ItemTemplate>

However, the error message is never displayed and the processing continues. What's strange is that the custom validation method is called, finds the field, and properly sets up e.IsValid to false. It do开发者_Go百科es not matter whether I check Page.IsValid or not, because the error message is not displayed anyway.

It works if I remove the CommandName="Delete" from the button.

With Google I found the following solution, which seems to indicate someone has had a similar issue:

http://devio.wordpress.com/2007/12/11/formview-delete-button-and-customvalidators/

But I want to make sure that this solution is the way to go. I mean, is custom validation really not supposed to work with a delete button in a databound control, seriously?


I've alrealy heard about a problem like that, he solved it by doing it entirely differently. Like, instead of the customValidator, he puts a Label set EnableViewState="False" and Visible="False" and he check on the delete event the conditions and put the response back into the label. Maybe it can't works for you too?

But, if you realy ask "Why?????", I know he didn't find the exact reason ...

0

精彩评论

暂无评论...
验证码 换一张
取 消