Groups | Blog | Home
all groups > asp.net datagrid control > december 2006 >

asp.net datagrid control : Button in GridView causes Invalid postback or callback argument



dev648237923
12/28/2006 5:35:29 PM
In my GridView I have a button in the Footer. When I click it it causes:

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.

If I change it to a LinkButton it does not cause the error???

See below I have a LinkButton and a Button -- the Button causes the error
while the LinkButton is fine -- odd???

------
There is nothing on the page except for the grid:

<asp:GridView ID="gvAlias" runat="server"
AutoGenerateColumns="False" CssClass="Font8"
ShowFooter="True"
OnRowDataBound="gvAlias_RowDataBound"
OnRowCancelingEdit="gvAlias_RowCancelingEdit"
OnRowCommand="gvAlias_RowCommand"
OnRowDeleting="gvAlias_RowDeleting"
OnRowEditing="gvAlias_RowEditing"
OnRowUpdating="gvAlias_RowUpdating"
[quoted text, click to view]
<Columns>
<asp:TemplateField ShowHeader="False" ItemStyle-CssClass="Font8">
<ItemTemplate>
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="lbDelete" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lbUpdate" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="lbCancel" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="lbInsert" text="New" font-size="8pt" runat="server"
CausesValidation="False" CommandName="Insert" CssClass="Font8" />
<asp:LinkButton ID="bInsert" text="New" font-size="8pt" runat="server"
CausesValidation="False" CommandName="Insert" CssClass="Font8" />
</FooterTemplate>
</asp:TemplateField>

<asp:BoundField DataField="ID" HeaderText="" ReadOnly="true"
HeaderStyle-CssClass="hidetd" FooterStyle-CssClass="hidetd"
ItemStyle-CssClass="hidetd" />
....

------
Code-behind:

protected void gvAlias_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
...
}
.....

Thank you for any ideas.

dev648237923
12/28/2006 6:01:34 PM
OK I fixed it --
It had to do with when I did databinding

[quoted text, click to view]

AddThis Social Bookmark Button