Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Replace the above lines in your aspx page with this..
<asp:TemplateField>
<ItemTemplate >
<asp:Button ID="Button1" runat="server" CommandName="Delete" Text="Delete"
OnClientClick="return confirm('Are you sure you want to delete this data Row?')" />
</ItemTemplate>
</asp:TemplateField>
Kindly mark this post as "Answer", if it helped you.
<asp:TemplateField>
<ItemTemplate >
<asp:Button ID="Button1" runat="server" CommandName="Delete" Text="Delete"
OnClientClick="return confirm('Are you sure you want to delete this data Row?')" />
</ItemTemplate>
</asp:TemplateField>
I'm still getting the same error, I don't understand where it comes
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim img As Image = DirectCast(e.Row.FindControl("Image1"), Image)
If img.ImageUrl = "NO" Then
img.ImageUrl = "Image1.jpg"
End If
If img.ImageUrl = "OK" Then
img.ImageUrl = "~Images/LigneHS.jpg"
End If
If img.ImageUrl = "" Then
img.ImageUrl = ""
End If
End If
End Sub
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
LabelDate.Text = System.DateTime.Now
SqlDataSource10.Insert()
' SqlDataSource3.DataBind()
' SqlDataSource6.DataBind()
TextBoxRemarques.Text = ""
GridView1.DataBind()
GridView1.Visible = True
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
LabelDate.Text = System.DateTime.Now
Dim u As MembershipUser
u = Membership.GetUser(User.Identity.Name)
If (My.User.IsAuthenticated) Then
LabelUtilisateurConnecté.Text = u.ToString()
Else : Response.Redirect("~/Account/Login.aspx")
End If
GridView1.DataBind()
End Sub
End Class
salim20001
Member
154 Points
507 Posts
Error with deleting button
May 04, 2012 05:43 PM|LINK
Hi,
In my grid view, this code is working well but deleting without confirmation
<asp:CommandField ShowDeleteButton="True" ButtonType="Button" DeleteText="Supprimer" />hwever this code give me an error
<asp:TemplateField> <ItemTemplate> <asp:Button ID="YesButton" runat="server" Text="Supprimer" OnClientClick="javascript:return confirm('Etes vous sûr ?');" CommandName="Delete" /> </ItemTemplate> </asp:TemplateField>I'm getting the following error:
Can you help me PLZ?
bbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Re: Error with deleting button
May 04, 2012 05:49 PM|LINK
Well, do you have this directive: <%@ Page EnableEventValidation="true" %>
at the top of your aspx page? If not, put it in and try it again.
basheerkal
Star
10672 Points
2426 Posts
Re: Error with deleting button
May 04, 2012 05:50 PM|LINK
Replace the above lines in your aspx page with this..
<asp:TemplateField> <ItemTemplate > <asp:Button ID="Button1" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this data Row?')" /> </ItemTemplate> </asp:TemplateField>(Talk less..Work more)
salim20001
Member
154 Points
507 Posts
Re: Error with deleting button
May 04, 2012 07:52 PM|LINK
I add it but still get the same error
salim20001
Member
154 Points
507 Posts
Re: Error with deleting button
May 04, 2012 07:54 PM|LINK
I'm still getting the same error, I don't understand where it comes
bbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Re: Error with deleting button
May 04, 2012 07:56 PM|LINK
Ok, I'm officially intrigued. Can you post both the aspx and code behind pages? There could be something else interferring.
salim20001
Member
154 Points
507 Posts
Re: Error with deleting button
May 04, 2012 08:14 PM|LINK
<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false" CodeFile="Ajout_planning.aspx.vb" Inherits="_Default" EnableEventValidation="True" %> <%@ Import Namespace="System.Web.Security" %> <%@ Register assembly="BasicFrame.WebControls.BasicDatePicker" namespace="BasicFrame.WebControls" tagprefix="BDP" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> <style type="text/css"> .style1 { width: 163px; } .style2 { width: 146px; } .style6 { width: 283px; } .style7 { width: 118px; } .style8 { width: 146px; text-align: left; } .style14 { width: 113px; text-align: center; } .style15 { width: 118px; text-align: left; } .style16 { width: 163px; text-align: left; } .style17 { font-weight: bold; text-align: left; width: 283px; } .style18 { width: 117px; } .style19 { text-align: center; width: 117px; } .style21 { font-weight: bold; text-align: left; width: 154px; } .style22 { width: 154px; text-align: center; } .style23 { text-align: left; } .style24 { width: 113px; text-align: left; } .style25 { text-align: left; width: 117px; } .style27 { width: 127px; } .style28 { width: 134px; font-weight: bold; text-align: left; } .style29 { width: 134px; } .style30 { font-weight: bold; text-align: left; width: 127px; } </style> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <h2> Bienvenue <asp:Label ID="LabelUtilisateurConnecté" runat="server" Text=""></asp:Label> On est le: <asp:Label ID="LabelDate" runat="server" Text=""></asp:Label> Maintenance des <asp:Label ID="LabelObjetIntervention" runat="server" Text="EQUIPEMENT"></asp:Label>S (Division <asp:Label ID="LabelDivision" runat="server" Text=""/>) </h2> <asp:Panel ID="Panel3" runat="server" Height="595px" style="margin-bottom: 47px" Width="100%"> <div id ="Section" runat=server> <table bgcolor="#f7f6f3" style="height: 30px; margin-top: 0px; width: 100%;"> <tr> <td bgcolor="#52CFEF" class="style16"> <strong>Division</strong></td> <td bgcolor="#52CFEF" class="style25"> <strong>Système</strong></td> <td bgcolor="#52CFEF" class="style15"> <strong>Site</strong></td> <td bgcolor="#52CFEF" class="style8"> <strong>Equipement</strong></td> <td bgcolor="#52CFEF" class="style24"> <strong>Num série </strong></td> <td bgcolor="#52CFEF" class="style23"> <strong>Fréquence</strong></td> </tr> <tr> <td class="style1"> <asp:DropDownList ID="DropDownListDivision" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource7" DataTextField="Division" DataValueField="Division"> </asp:DropDownList> </td> <td class="style18"> <asp:DropDownList ID="DropDownListSystème" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource8" DataTextField="Système" DataValueField="Système"> </asp:DropDownList> </td> <td class="style7"> <asp:DropDownList ID="DropDownListSite" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="Site" DataValueField="Site" Height="20px" Width="80px"> </asp:DropDownList> </td> <td class="style2"> <asp:DropDownList ID="DropDownListEquipementHS" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="Equipement" DataValueField="Equipement" Height="23px" Width="141px"> </asp:DropDownList> </td> <td class="style14"> <a /> <asp:DropDownList ID="DropDownListEquipementHS0" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource12" DataTextField="N_série" DataValueField="ID_équipement" Height="22px" Width="90px" style="margin-left: 0px"> </asp:DropDownList> </a> </td> <td class="style19"> <a /> <asp:DropDownList ID="DropDownListTypeIntervention" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource9" DataTextField="Type_maintenance" DataValueField="Type_maintenance" Height="22px"> </asp:DropDownList> </a> </td> </tr> </table> <table bgcolor="#f7f6f3" style="height: 56px; width: 100%"> <tr> <td bgcolor="#52CFEF" class="style17"> Remarques</td> <td bgcolor="#52CFEF" class="style28"> Date intervention</td> <td bgcolor="#52CFEF" class="style30"> Date intervention au plus tard</td> <td bgcolor="#52CFEF" class="style21"> </td> </tr> <tr> <td class="style6"> <asp:TextBox ID="TextBoxRemarques" runat="server" Height="20px" Width="334px"></asp:TextBox> </td> <td class="style29"> <BDP:BasicDatePicker ID="TextBoxDateDébutIntervention" runat="server" Height="20px" DisplayType="TextBox" Width="147px"/> </td> <td class="style27"> <BDP:BasicDatePicker ID="TextBoxDateFinIntervention" runat="server" Height="20px" DisplayType="TextBox" Width="147px"/> </td> <td class="style22"> <asp:Button ID="Button1" runat="server" style="margin-left: 0px" Text="Ajouter" Width="117px" /> </td> </tr> </table> </div> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" Height="131px" style="text-align: center; margin-top: 0px; font-weight: 700; font-size: small; margin-left: 0px;" Width="100%" ForeColor="#000073" GridLines="None" DataKeyNames="ID_planning"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <Columns> <asp:BoundField DataField="Division" HeaderText="Division" SortExpression="Division" /> <asp:TemplateField HeaderText="Date" SortExpression="Date" > <ItemTemplate> <%#Eval("Date", "{0:dd-MM-yyyy}")%> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Date_fin" HeaderText="Jusqu'au" SortExpression="Date_fin" /> <asp:BoundField DataField="Equipement" HeaderText="Equipement" SortExpression="Equipement" /> <asp:BoundField DataField="Type_planification" HeaderText="Fréquence" SortExpression="Type_planification" /> <asp:TemplateField HeaderText="Etat" SortExpression="Etat" > <ItemTemplate> <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Etat")%>' /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Utilisateur" HeaderText="Ajouté par" SortExpression="Utilisateur" /> <asp:BoundField DataField="Remarques" HeaderText="Remarques" SortExpression="Remarques" /> <asp:BoundField DataField="Système" HeaderText="Système" SortExpression="Système" /> <asp:BoundField DataField="Site" HeaderText="Site" SortExpression="Site" /> <asp:BoundField DataField="N_série" HeaderText="N_série" SortExpression="N_série" /> <asp:CommandField ShowDeleteButton="True" ButtonType="Button" DeleteText="Supprimer" /> <asp:TemplateField> <ItemTemplate> <asp:Button ID="YesButton" runat="server" Text="Supprimer" OnClientClick="javascript:return confirm('Etes vous sûr ?');" CommandName="Delete" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate > <asp:Button ID="Button1" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this data Row?')" /> </ItemTemplate> </asp:TemplateField> </Columns> <EditRowStyle BackColor="#999999" /> <FooterStyle BackColor="#000073" ForeColor="White" Font-Bold="True" /> <HeaderStyle BackColor="#000073" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <RowStyle ForeColor="#000073" BackColor="#F7F6F3" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#000073" /> <SortedAscendingCellStyle BackColor="#E9E7E2" /> <SortedAscendingHeaderStyle BackColor="#506C8C" /> <SortedDescendingCellStyle BackColor="#FFFDF8" /> <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> </asp:GridView> <br /> </asp:Panel> <asp:Panel ID="Panel1" runat="server"> <asp:SqlDataSource ID="SqlDataSource10" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Planning]" DeleteCommand="DELETE FROM [Planning] WHERE [ID_planning] = @ID_planning" InsertCommand="INSERT INTO [Planning] ([Date], [Date_fin], [Type_planification], [ID_équipement], [Utilisateur], [Remarques], [Etat]) VALUES (@Date, @Date_fin, @Type_planification, @ID_équipement, @Utilisateur, @Remarques, @Etat)" UpdateCommand="UPDATE [Planning] SET [Date] = @Date, [Date_fin] = @Date_fin, [Type_planification] = @Type_planification, [ID_équipement] = @ID_équipement, [Utilisateur] = @Utilisateur, [Remarques] = @Remarques, [Etat] = @Etat WHERE [ID_planning] = @ID_planning"> <DeleteParameters> <asp:Parameter Name="ID_planning" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:ControlParameter ControlID="TextBoxDateDébutIntervention" PropertyName="Text" Name="Date" Type="DateTime" /> <asp:ControlParameter ControlID="TextBoxDateFinIntervention" PropertyName="Text" Name="Date_fin" Type="DateTime" /> <asp:ControlParameter ControlID="DropDownListTypeIntervention" PropertyName="SelectedValue" Name="Type_planification" Type="String" /> <asp:ControlParameter ControlID="DropDownListEquipementHS0" PropertyName="SelectedValue" Name="ID_équipement" Type="Int32" /> <asp:ControlParameter ControlID="LabelUtilisateurConnecté" PropertyName="Text" Name="Utilisateur" Type="String" /> <asp:ControlParameter ControlID="TextBoxRemarques" PropertyName="Text" Name="Remarques" Type="String" /> <asp:Parameter Name="Etat" Type="String" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="Date" Type="DateTime" /> <asp:Parameter Name="Date_fin" Type="DateTime" /> <asp:Parameter Name="Type_planification" Type="String" /> <asp:Parameter Name="ID_équipement" Type="Int32" /> <asp:Parameter Name="Utilisateur" Type="String" /> <asp:Parameter Name="Remarques" Type="String" /> <asp:Parameter Name="Etat" Type="String" /> <asp:Parameter Name="ID_planning" Type="Int32" /> </UpdateParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [Equipement] FROM [Equipements] WHERE ( (@Division='NULL' or [Division] = @Division) AND (@Système = 'NULL' or [Système] = @Système) AND (@Site='NULL' or [Site] = @Site) ) "> <SelectParameters> <asp:ControlParameter ControlID="DropDownListDivision" Name="Division" PropertyName="SelectedValue" Type="String" DefaultValue="NULL" /> <asp:ControlParameter ControlID="DropDownListSystème" DefaultValue="NULL" Name="Système" PropertyName="SelectedValue" Type="String" /> <asp:ControlParameter ControlID="DropDownListSite" DefaultValue="NULL" Name="Site" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource5" runat="server"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Vue_planning]" DeleteCommand="DELETE FROM [Planning] WHERE [ID_planning] = @ID_planning" > <DeleteParameters> <asp:Parameter Name="ID_planning" Type="Int32" /> </DeleteParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource7" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [Division] FROM [Equipements]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource8" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [Système] FROM [Equipements] WHERE (@Division='NULL' or [Division] = @Division)"> <SelectParameters> <asp:ControlParameter ControlID="DropDownListDivision" Name="Division" PropertyName="SelectedValue" Type="String" DefaultValue="NULL" /> </SelectParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource9" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [Type_maintenance] FROM [Types_planning]"> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [Id_équipement_HS] FROM [Equipements_HS] WHERE ([Equipement] = @Equipement) order by [Id_équipement_HS] desc"> <SelectParameters> <asp:ControlParameter ControlID="DropDownListEquipementHS" Name="Equipement" PropertyName="SelectedValue" Type="String" /> </SelectParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource11" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT * FROM [Equipements] WHERE (([Système] = @Système) AND ([Division] = @Division)) ORDER BY [Equipement]"> <SelectParameters> <asp:ControlParameter ControlID="DropDownListSystème" Name="Système" PropertyName="SelectedValue" /> <asp:ControlParameter ControlID="DropDownListDivision" Name="Division" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource12" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [N_série], [ID_équipement] FROM [Equipements] WHERE ( (@Division='NULL' or [Division] = @Division) AND (@Système = 'NULL' or [Système] = @Système) AND (@Site='NULL' or [Site] = @Site) AND (@Equipement='NULL' or [Equipement] = @Equipement ) ) "> <SelectParameters> <asp:ControlParameter ControlID="DropDownListDivision" Name="Division" PropertyName="SelectedValue" DefaultValue="NULL" /> <asp:ControlParameter ControlID="DropDownListSystème" DefaultValue="NULL" Name="Système" PropertyName="SelectedValue" /> <asp:ControlParameter ControlID="DropDownListSite" DefaultValue="NULL" Name="Site" PropertyName="SelectedValue" /> <asp:ControlParameter ControlID="DropDownListEquipementHS" DefaultValue="NULL" Name="Equipement" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [Site] FROM [Equipements] WHERE ((@Division='NULL' or [Division] = @Division) and (@Système ='NULL' or [Système] = @Système))"> <SelectParameters> <asp:ControlParameter ControlID="DropDownListDivision" Name="Division" PropertyName="SelectedValue" DefaultValue="NULL" /> <asp:ControlParameter ControlID="DropDownListSystème" DefaultValue="NULL" Name="Système" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSource> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </asp:Panel> </asp:Content>Partial Class _Default Inherits System.Web.UI.Page Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then Dim img As Image = DirectCast(e.Row.FindControl("Image1"), Image) If img.ImageUrl = "NO" Then img.ImageUrl = "Image1.jpg" End If If img.ImageUrl = "OK" Then img.ImageUrl = "~Images/LigneHS.jpg" End If If img.ImageUrl = "" Then img.ImageUrl = "" End If End If End Sub Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click LabelDate.Text = System.DateTime.Now SqlDataSource10.Insert() ' SqlDataSource3.DataBind() ' SqlDataSource6.DataBind() TextBoxRemarques.Text = "" GridView1.DataBind() GridView1.Visible = True End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load LabelDate.Text = System.DateTime.Now Dim u As MembershipUser u = Membership.GetUser(User.Identity.Name) If (My.User.IsAuthenticated) Then LabelUtilisateurConnecté.Text = u.ToString() Else : Response.Redirect("~/Account/Login.aspx") End If GridView1.DataBind() End Sub End Classbbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Re: Error with deleting button
May 04, 2012 08:54 PM|LINK
You have two delete buttons which could be the problem:
<asp:BoundField DataField="N_série" HeaderText="N_série" SortExpression="N_série" /> <asp:CommandField ShowDeleteButton="True" ButtonType="Button" DeleteText="Supprimer" /> <asp:TemplateField> <ItemTemplate> <asp:Button ID="YesButton" runat="server" Text="Supprimer" OnClientClick="javascript:return confirm('Etes vous sûr ?');" CommandName="Delete" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate > <asp:Button ID="Button1" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this data Row?')" /> </ItemTemplate> </asp:TemplateField>salim20001
Member
154 Points
507 Posts
Re: Error with deleting button
May 04, 2012 10:16 PM|LINK
No I had the problem, before having 2 buttons (with only one button) , I just added several buttons of delete to try to see if the problem persists
I get the same error when trying to add a button to update or delete, but when using the "
) it worksQin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Error with deleting button
May 08, 2012 08:48 AM|LINK
Hi,
Turn off the enableEventValidation="false" in page tag.
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework