Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi i'm developing the asp.net project.here when i'm click the textbox in
gridview edit,display the error message.
The error message as

"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"

here the code as
HTML
<asp:GridView ID="sview" runat="server" SelectedIndex="0" OnRowDataBound ="Table_DataBound"
                style="font-family: Verdana; font-size: X-Small; font-weight: bold; top: 13px; left: 1px; position: absolute; height: 20px; width: 646px; border: 1px Solid Black"
                 OnRowEditing ="Table_Edit" OnRowUpdating ="Table_Update" OnRowCancelingEdit ="Table_Cancel">
                <columns>
                <asp:TemplateField  HeaderText="subname" HeaderStyle-HorizontalAlign ="Left" >
                    <edititemtemplate> 
                        <asp:TextBox ID="txtsubname" runat="server" Text='<%# Bind("subname") %>'> 
                    </edititemtemplate> 
                    <footertemplate> 
                        <asp:TextBox ID="txtNewName" runat="server" > 
                    </footertemplate> 
                    <itemtemplate> 
                        <%# Eval("subname") %>
                    </itemtemplate> 
                
                 <asp:TemplateField HeaderText="sname" HeaderStyle-HorizontalAlign="Left"> 
                    <edititemtemplate> 
                        <asp:DropDownList ID="cmbgname" runat="server" DataTextField="Typename" DataValueField="Id">  
                    </edititemtemplate> 
                    <itemtemplate> 
                        <%# Eval("gname") %>
                    </itemtemplate> 
                    <footertemplate> 
                        <asp:DropDownList ID="cmbgname" runat="server" DataTextField="Typename" DataValueField="Id">  
                    </footertemplate> 
             
                    <asp:CommandField SelectText="" ShowSelectButton="True" />
                    <asp:CommandField CancelText="" EditText="" ShowEditButton="True" 
                        UpdateText="" />
                </columns>
                <SelectedRowStyle BackColor="#5691FE" />
                <HeaderStyle BackColor="#D6BBBA" HorizontalAlign="Left" />



C#
protected void Table_Edit(object sender, object e)
{
    GridViewEditEventArgs ex = new GridViewEditEventArgs(sview.SelectedIndex);
    sview.EditIndex = ex.NewEditIndex;
    BindData();
}
protected void Table_Update(object sender, object e)
{
    DataTable dt = (DataTable)Session["ATable"];
    GridViewRow row = sview.Rows[sview.EditIndex];
    if (row.Cells[6].Text.Equals("Y"))
    {
        dt.Rows[row.DataItemIndex]["subname"] = ((TextBox)(row.Cells[2].FindControl (""))).Text;
        dt.Rows[row.DataItemIndex]["gname"] = ((DropDownList)(row.Cells[4].FindControl(""))).SelectedValue;
    }
    sview.EditIndex = -1;
    DataBind();
}
protected void Table_Cancel(object sender, object e)
{
    sview.EditIndex = -1;
    DataBind();
}


[edit]Code blocks added to preserve formatting - OriginalGriff[/edit]
Posted
Updated 19-Dec-10 1:33am
v2

1 solution

As error clearly specifies: "Event validation is enabled using <%pages enableEventValidation="true"%> in configuration or <%@ Page EnableEventValidation="true"%> in a page", just set enableEventValidation to false for the page and it should be good to go.
 
Share this answer
 
v2
Comments
REJI KURU 20-Dec-10 0:34am    
Thanks Friend

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