0

I have a gridview with delete action.. particular row needs to be updated on it. I am getting errors when doing that.

Invalid postback or callback argument. Event validation is enabled using 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.

How to write client side event for the gridview.

my gridview

please tel me how to rectify this errors.. requirement is to on clicking delete button, that row needs to be updated to particular set values..

James
  • 11
  • 4

2 Answers2

0

You are doing a wrong call to AddWithValue method. You are specifying a SqlDbType when AddWithValue is supposed to do it implicitly:

string yourId = "1";

con.Open();
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Id", yourId);

Also, I don´t see where you have the value Id that is supposed to be passed as parameter. I added yourId variable since there is not id value.

If you want to specify the type, dont use AddWithValue, use Add, instead:

string yourId = "1";

con.Open();
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@Id", SqlDbType.NVarChar).Value = yourId;

Also, are you sure that ID column should be NVarChar??

NicoRiff
  • 4,803
  • 3
  • 25
  • 54
  • problem is not that.. on clicking delete button i am getting error.. how to handle that be client side event and run the code – James Feb 24 '17 at 12:35
  • @James the error is that one for sure. There is not overload for AddWithValue that expects a SqlDbType – NicoRiff Feb 24 '17 at 12:36
  • yes i did change that but still i am getting error, its because need to write client side event for grid view delete button. how to write? – James Feb 24 '17 at 12:41
  • @James take a look at this: http://stackoverflow.com/questions/228969/invalid-postback-or-callback-argument-event-validation-is-enabled-using-page – NicoRiff Feb 24 '17 at 12:47
  • Yes it is a solution but it is nor recommended to use event validation false.. we need to write some client side event like row delete – James Feb 24 '17 at 12:51
0
private void Page_Load()
    {
        if (!IsPostBack)
        {    
            //Bind Date
        }
    }

alterantively you can

EnableEventValidation="false"

but that is not recommended

  • yes i need to write client side event for row delete how to write?? – James Feb 24 '17 at 12:43
  • http://www.c-sharpcorner.com/UploadFile/9f0ae2/gridview-edit-delete-and-update-in-Asp-Net/ Educate and read. –  Feb 24 '17 at 12:45