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

I have two asp.net web pages 1)CustomerVendorDetails 2)AddEditCustomerVendorDetails.

CustomerVendorDetails page is used to display all customer/vendor details in a gridview, AddEditCustomerVendorDetails page is used to Add and Edit customer/vendor details.


In CustomerVendorDetails page gridview is used to display the all customer/vendor details, if user want to edit a particula customer/vendor details he/she will click on Edit button of corresponding row, all the field values of that row will redirect to correspondig controls in AddEditCustomerVendorDetails page.

Here i used Imagebutton instade of linkbutton for row edit that code is as follows:
XML
<asp:TemplateField>
        <ItemTemplate>
                      <asp:ImageButton ID="ibEdit" runat="server" CausesValidation="False" CommandName="Edit"
                          ImageUrl="~/images/Edit.gif" ToolTip="Edit" CommandArgument='<%# Container.DataItemIndex %>'></asp:ImageButton>
                      </ItemTemplate>
       </asp:TemplateField>


Gridviews RowCommand event code is as follows:
C#
protected void gvCustomerVendorDetails_RowCommand(object sender, GridViewCommandEventArgs e)
       {
           if (e.CommandName == "Edit")
           {
               int igvCustomerVendorDetailsIndex = Convert.ToInt32(e.CommandArgument);
               GridViewRow gvCustomerVendorDetailsRow = gvCustomerVendorDetails.Rows[igvCustomerVendorDetailsIndex];
               Session["CusVenID"] = gvCustomerVendorDetails.DataKeys[igvCustomerVendorDetailsIndex].Value;
               Response.Write("~/AddEditCustomerVendorDetails.aspx?AddEdit=Edit");
           }
       }

Whenever i clicks on ImageButton its showing an error that is:
System.ArgumentException: 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.


please any body help me to solve this error.

Thanks in advance
Uday
Posted
Comments
Anuja Pawar Indore 11-Oct-11 7:33am    
Is your grid inside update panel?

Try setting
EnableEventValidation="false"

in the page directive.
 
Share this answer
 
v2
Comments
udaysimha 11-Oct-11 3:50am    
Hi thanks for your reply.
I tryed the way you suggested it not showing any error but Rowcommand event is not fireing, please can you help me.
Hi,

My suggestion is check your data dinding must be in following
C#
//under pageload
if(!isPostBack)
{
  fillgrid();
}


And replace your button image with following code

ASP.NET
<asp:linkbutton id="Linkbut" runat="server" commandname="" commandargument="" xmlns:asp="#unknown">
<img src="" width="" height="" />
</asp:linkbutton>


All the Best
 
Share this answer
 
I too got the same problem 3 months back.Bind data to gridview in page load.
 
Share this answer
 
<asp:TemplateField HeaderText="View" ShowHeader="False">
                                <itemtemplate>
                                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="View"
                                        Text="View" CommandArgument='<%# Eval("intSchoolId")%>'>
                                </itemtemplate>


in code:Dont write ur Code in Command Argument In Gridview There is Edit Template Option Just u select Image Button and Double Click ok.

Like this it will come:

protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string Mode = "A";
        pr.Mode = Mode;
        dt = new DataTable();
        dt = logic.GetAlldetails(pr);
        Session["dataset"] = dt;
        int x;
        x = grid.FocusedRowIndex;
        Response.Redirect("ConstructLogic.aspx?intSchoolId=" + x + "");
    }

Just analize this

Regards,

Anilkumar.D
 
Share this answer
 
v3

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