Click here to Skip to main content
15,886,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

I was trying an application on ASP.NET 4.0 using DataGrid with 2 data columns and 2 columns bearing "Edit/Update/Cancel" and "Add/Delete" button. The grid is populating nicely but as I am clicking on Add or Edit button, I am getting the following error:
-------------------------------------------------------
Server Error in '/' Application.
--------------------------------------------------------------------------------

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.


-------------------------------------------------------

I tried many forums and problem solving sites but could not find a proper satisfying solution in the form of implementation. If anyone could help me out of this problem. it would be great.

the page is designed as under:
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="DataGridApp.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
</head>
<body>
    <form id="form1"  method="post"  runat="server">
    <div>
    
        <asp:DataGrid ID="dg1" runat="server" AutoGenerateColumns="False" 
            BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" Width="500px" 
            Font-Bold="False" Font-Italic="False" Font-Overline="False" 
            Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" 
            oncancelcommand="dg1_Cancel" ondeletecommand="dg1_Delete" 
            oneditcommand="dg1_Edit" onitemcommand="dg1_ItemCommand" 
            onitemdatabound="dg1_DataBound" onupdatecommand="dg1_Update" ShowFooter="True">
            <columns>
                <asp:BoundColumn HeaderText="S.No" ReadOnly="True">
                    <itemstyle font-bold="False" font-italic="False" font-overline="False">
                        Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" 
                        VerticalAlign="Middle" />
                
                <asp:TemplateColumn HeaderText="Country">
                    <itemstyle font-bold="False" font-italic="False" font-overline="False">
                        Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" 
                        VerticalAlign="Middle" />
                        <itemtemplate>
                                <%# DataBinder.Eval(Container.DataItem, "Country")%>
								<input type="hidden"  runat="server" name="Country" id="Country" value='<%# DataBinder.Eval(Container.DataItem, "Country") %>' />
                        </itemtemplate>
                        <edititemtemplate>
                            <%--<asp:TextBox id="CName" MaxLength="50" Width="150" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Country") %>'/>--%>
							<input type="hidden"  runat="server" name="Country" id="Country" value='<%# DataBinder.Eval(Container.DataItem, "Country") %>' />
                        </edititemtemplate>
                        <footertemplate>
                            <asp:TextBox id="add_Country" MaxLength="50" Width="150" Runat="server">
                        </footertemplate>
                
                <asp:TemplateColumn HeaderText="Capital">
                    <itemstyle font-bold="False" font-italic="False" font-overline="False">
                        Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" 
                        VerticalAlign="Middle" />
                        <itemtemplate>
                            <%# DataBinder.Eval(Container.DataItem, "Capital")%>
                        </itemtemplate>
                        <edititemtemplate>
                            <asp:TextBox id="CapName" MaxLength="50" Width="150" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Capital") %>'/>
							<input type="hidden"  runat="server" name="Capital" id="Capital" value='<%# DataBinder.Eval(Container.DataItem, "Capital") %>' />
                        </edititemtemplate>
                        <footertemplate>
                            <asp:TextBox id="add_Capital" MaxLength="50" Width="150" Runat="server">
                        </footertemplate>
                
                <asp:EditCommandColumn ButtonType="PushButton" CancelText="Cancel" 
                    EditText="Edit" HeaderText="Edit" UpdateText="Update">
                    <HeaderStyle Width="150px" />
                    <itemstyle font-bold="False" font-italic="False" font-overline="False">
                        Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" 
                        VerticalAlign="Middle" />
                
                <asp:TemplateColumn HeaderText="Add/Delete">
                    <footerstyle font-bold="False" font-italic="False" font-overline="False">
                        Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" 
                        VerticalAlign="Middle" />
                    <itemstyle font-bold="False" font-italic="False" font-overline="False">
                        Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" 
                        VerticalAlign="Middle" />
                        <itemtemplate>
                            <asp:Button CommandName="Delete" Text="Delete" ID="btnDel" Runat="server" />
                        </itemtemplate>
                        <footertemplate>
                            <asp:Button CommandName="Insert" Text="Add" ID="btnAdd" Runat="server" />
                        </footertemplate>
                
            </itemstyle></footerstyle></itemstyle></itemstyle></itemstyle></itemstyle></columns>
            <edititemstyle font-bold="False" font-italic="False" font-overline="False">
                Font-Strikeout="False" Font-Underline="False" />
            <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" 
                VerticalAlign="Middle" />
        
        <br />
        <center><asp:Label ID="lblMsg" Text="" runat="server"></center>
    </edititemstyle></div>
    </form>
</body>
</html>

Thanks in advance

IB
Posted
Updated 30-Nov-12 2:09am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900