Se ClientScriptManager.RegisterForEventValidation method for registering postback data or callback for validation

Guys, I have a usercontrol in my asp.net 3.5 application, and I pass some plain text on a button click event. The button is in usercontrol. but when I fire the event, I get the following error:

Invalid callback or callback argument. Event checking is enabled using the configuration or <% @Page EnableEventValidation = "true"%> in page. For security reasons, this function checks that the arguments of the postback or callback event from the server that originally represented them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method to register the postback data or callback for validation.

when I set EnableEventValidation = "false" to the web form page, for example, hit. he fires an event;

<%@ Page EnableEventValidation="false" %> 

but I think it should not be a good idea to establish this false. So what is the alternative here? there the error says that it uses the ClientScriptManager.RegisterForEventValidation method to register the postback or callback data for validation. 'but where am I going to register this thing? thanks!

In addition, I use some AjaxControlToolkit controls inside my usercontrol and some jquery files.

+7
source share
6 answers

The problem with ASP.NET 2.0 event checking is that it is all or nothing and a little heavy. I read an article that explains what you should do here.

Basically, you need to register child user controls using an event-checking mechanism.

 C# protected override void Render(HtmlTextWriter writer) { // Register controls for event validation foreach (Control c in this.Controls) { this.Page.ClientScript.RegisterForEventValidation( c.UniqueID.ToString() ); } base.Render(writer); } VB Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter) For Each aControl As Control In Me.Controls Me.Page.ClientScript.RegisterForEventValidation(aControl.UniqueID.ToString) Next aControl MyBase.Render(writer) End Sub 

Now this may not solve your problem, because I'm not sure how you return the string. Another article explains that event validation is a combination of the unique identifier of the control and all the values ​​that it can pass. If you use the command value to convey text, you may have problems with this task.

If the event causing the problem is a click, then registering the controls of the user control should do the trick.

+3
source

try

 if (!Page.IsPostBack) 

before loading and binding data in datagrid

+2
source

In my situation, I tried to update the GridViews data source to page_load , and I forgot to check if the request was postback, so my source tried to change, and it threw this error. As soon as I checked for the post, it worked fine. Hope this helps someone in the future.

  if (Page.IsPostBack == false) { this.sqlObj = new SqlServer(ConfigurationManager.ConnectionStrings["PdfReceiverConnectionString"].ToString()); this.populateDataGrid(); } 
+1
source

You can leave it turned on and then register your control to check for events. Add the following call to the life cycle of the PreRender or Render page, then your control should work without having to disable eventValidation:

  Page.ClientScript.RegisterForEventValidation(this.UniqueID); 
0
source

Check your HTML nested from tags will also cause

0
source

check the code below:

 if(!IsPostBack) { //Bind your gridView } 
0
source

All Articles