1

I am working with a sharepoint server 2013 installation, which is comprised of a number of webparts, built with VS 2013. The webpart I am currently working with is meant to manage address changes for users, and it calls out to a webservice to validate that the address is 'correct'.

(http://www.strikeiron.com/product-list/address/north-american-address-verification-2/)

I am using an <asp:updatepanel> with an <asp:formview> within it to handle the updates asynchronously without refreshing the page while validating.

The problem I am having is that the verification only works ONCE. If I try to validate again, I get the error message:

Error: Sys.WebForms.PageRequestManagerServerErrorException: 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've done some googling on this error, and there is a defined cause, and some defined solutions for it. However, I'm struggling with how to implement these solutions in sharepoint. For example, here is a similiar question:

Saving Page with WebPart error Invalid postback or callback argument

which led me to here: http://odetocode.com/Blogs/scott/archive/2006/03/22/asp-net-event-validation-and-invalid-callback-or-postback-argument-again.aspx

basically, the reason this is happening is that something is somehow "different" on my page the second time I submit, so it doesn't pass validation anymore. Trouble is, I am not sure exactly what it is that is different. I have buttons that appear and disappear, as well as a province dropdown that repopulates based on the country selected (or disappears if not canada or US). I do give all the controls an ID, but then sharepoint goes and tags a bunch of stuff on to the ID so they aren't necessarily the same each time.

the potential solutions are:

  1. disable eventValidation globally

    <system.web> <pages enableEventValidation="false"/> </system.web>

I can't use this because I don't have a web.config in my web part. I don't want to disable event validation for the entire sharepoint. Even if I could, that would be far out of the scope of dealing with this one issue.

  1. disable event validation just for this page

    <%@ Page EnableEventValidation="false" ... %>

I can't do this because webparts don't have a @Page directive. Is there some equivalent for webparts? I tried simply doing this in the page load via Page.EnableEventValidation = false;

this produces the error message on build:

the 'EnableEventValidation' property can only be set in the page directive or in the <pages> configuration section.

OK, so that's it for the easy methods, looks like I'm going to have to go the hard way, and register the event via: ClientScriptManager.RegisterForValidation as noted above though, This fix, however, requires that you "register" every possible value for the control!

I have a list of 50+ states and 16 or so provinces, do I really need to register all those items separately? I also have two more textboxes that show up for the latitude and longitude, which are also submitted after a validation, perhaps those also need to be included. The trouble is I am not sure exactly what needs to be registered in this way.

In the comments of the link, it's noted that:

I'd like to add that it is much easier to debug this error (especially when you are doing something more complex than adding a value to a dropdown) if you override the RaisePostBackEvent method on the page and add a breakpoint in the method. This way you can see what is being passed to the ValidateEvent method and know what exactly to pass to the RegisterEventForValidation method.

`protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)
{
string strArgs = eventArgument;
base.RaisePostBackEvent(sourceControl, eventArgument);
}`

this may help me figure out exactly what is different about the page. I tried adding it to my page, but I get this error message:

'UpdateAddresses.VisualWebPart1.VisualWebPart1UserControl.RaisePostBackEvent(System.Web.UI.IPostBackEventHandler, string)': no suitable method found to override

So, that's a pretty detailed explanation of the problem I am having.

Possible Solutions in order of preference:

  1. tell me how to disable event validation for a single web part
  2. tell me how to disable event validation for a sharepoint page (i tried editing page in SP, the page directive is not something I can change here, only the page contents. but found a way to actually edit the page directive and disable event validation. this also did not work, the same error occurs.)
  3. tell me how to disable event validation for the entire sharepoint site (i'd really rather not do this)
  4. tell me how to use ClientScriptManager.RegisterForValidation in my scenario, first by discovering WHAT I need to register, and then making the calls.

Thanks for your time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.