Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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:
<%@ 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 30-Nov-12 1:53am
Edited 30-Nov-12 2:09am
(no name)83.4K
v2

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

  Print Answers RSS
0 OriginalGriff 389
1 Sergey Alexandrovich Kryukov 375
2 Maciej Los 295
3 King_Fisher 160
4 Garth J Lancaster 158
0 Sergey Alexandrovich Kryukov 11,069
1 OriginalGriff 5,743
2 Maciej Los 5,649
3 CPallini 3,879
4 BillWoodruff 3,584


Advertise | Privacy | Mobile
Web03 | 2.8.141030.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100