DataGrid editcommand in UpdatePanel - asp.net

My page uses Multiview with 3 views.
the third view for searching and has a datagrid in updatepanel, in datagrid has editcommand column. when user click edit on edicommand comlumn, the activeviewindex of multiview set to 1, but it throws and postback error.
"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 think my problem is activeviewindex method, because when user click edit on editcommandcolumn, I set activeviewindex to 1, while my datagrid is inside updatepanel and updatepanel in view 3. How can I fix it?

I think there are some options to consider:
If you don't care too much about security you can turn off event validation on that page.
Why are you using an update panel if when editing the grid you go to another view? Consider giving it up.
Try to put all three views within a single update panel.

Related

ASP.NET Webforms cause error on submit if listbox item is added by javascript and is selected

I have a listbox which is part of a composite control.
I add items by javascript. If I submit without selecting items(click on one or more of them), it works fine, but if I click on one of the items, it causes the following error.
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.
I tried to register some possible values using Page.ClientScript.RegisterForEventValidation and it works fine for that values(in case when I selected one of them). So if I register all possible values, then i won't have problems. But the possible values are about 29000 int values.In my opinion, calling a service to get and register values is not a good solution.
Is there any other approach to solve this?

Invalid postback or callback argument[ASP.NET]

I have an asp.net page with asp dropdown control, dropdown user control, componentArt callback control and submit button.
On selection of any item from asp.net dropdown control, it makes a server side call(like AJAX) and fill-in the dropdown user control.
Now user select item from the user control drop down and click the submit button to postback the form.
On clicking of submit button the below exception throws.
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.
Kindly tell the reason for getting this exception and provide the solution.

Gridview with row being edited causing error when form submitted

Using ASP.NET VB, I have a form with some text boxes and a Gridview. If a user clicks the Edit button on a row in the gridview, and then tries to submit the form with a row still in edit mode on the Gridview, this error is generated -
"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. "
Any idea how to prevent this error??
just go to web.config and make it false.
i also face that error and i fixed it by doing this.
check these link as reference
http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=35528
http://channel9.msdn.com/forums/TechOff/155642-Invalid-postback-or-callback-argument-Wants-event-validation-enabled/
check my answer if you get your answer and vote it.thanx

purpose for <pages enableEventValidation="false">

I've used the following in web.config
<pages enableEventValidation="false">
This corrects a problem we've been having with Ajax.
We have a web page that if you browse to directly using a standard HTML hyperlink works fine.
If you browse to the page from another page via link inside a gridview and response.redirecting in the RowCommand event to the page passing an ID in the querystring. The page throws errors from controls inside the panel stating
"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. "
I'm happy to leave the page validation as false as it seems to have had no other effect.
Any ideas what's happening?
Read the documentation.
EDIT: For security reasons, it's probably best to leave it set to true wherever you can.
I would therefore recommend that you set it to false only on the individual AJAX pages where it causes problems, while leaving it true in web.config.
From here
Invalid PostBack or CallBack argument error is basically raise because of Event Validation feature. The EventValidation feature is a new feature in ASP.NET 2.0, and provides an additional level of checks to verify that a postback from a control on the client is really from that control and not from someone malicious using something like a cross-site script injection to try and manipulate things. It is part of our overall strategy of increasingly adding security in depth levels to the programming model -- so that developers can be secure by default even if they forget to add security checks of their own.
Now, Invalid PostBack or CallBack argument error may occur when you are firing click event and the object is rebinding or its properties are changed in Page_Load event or someone is trying to hack into your system with cross site scripting. Each time .Net Framework render a page then it associate a unique Guid for all the controls. When binding a gridview or repeater, on each databind framework will associate a new guid for the contorl. So every time when you are firing event make sure Page_Load event does not change the control, because if the control changed the it will have a different Guid which have acutally fired the event for postback. Here are some scenario with this error.
1) Invalid Postback or Callback argument in GridView Problem may be: You are binding data in Page_Load event with either Object Data Source or Manual Binding with function call. This will make your GridView bind data on every event fire of any control. When you are firing any GridView command with OnRowCommand, before RowCommand fire your GridView will rebind and all control within it will be assigned to new id. So RowCommand could not get the item which have fired the event. Solution for Invalid Postback or Callback argument in GridView: You can bind your data within this if condition
if (!IsPostBack)
{
//Your code for Bind data
}
This code will definitely give you solution if this not work then check whether any other control is not giving error.
There is one thing worth adding here: If you want to disable the event validation for a specific control, rather than the entire page, there is a workaround documented here and here (and now referenced in the relevant Connect suggestion):
Simply subclass the relevant WebControl class, and don't set the SupportsEventValidation attribute on the subclass. The subclass will be exempt from event validation.

DataGrid Paging Problem in IE

I have a single templated column in a DataGrid, in an ASP.NET 2 web sites. The DataGrid is paged, with ten rows per page.
In Firefox, all is good, as nearly always, but when I view the site trough IE, I get the following exception:
Invalid postback or callback argument. Event validation is enabled using in configuration or <%# Page EnableEventValidation="true" %> in a page.
Any ideas on what may cause this?
I have seen this before in relation with dynamically added controls. Outside your DataGrid are you programatically adding controls to your page?
If so ensure that they are constructed, named, and added to the page on the Page's Init event otherwise you can possible gunk up the event tracking, and validation.

Resources