Question on Cascade dropdowns

Aug 12, 2010 at 1:38 PM

Hello M

I have a similar requirement on a SharePoint project that I am working on.

I have 2 dropdowns and a text field on a SharePoint list which are supposed to trigger the values of the dropdown on the 3rd dropdown.

1st Field: Dropdown: Name-> Country (choice type)

2nd Field: Dropdown: Name -> Category (choice type)

3rd Field: TextBox: Name -> Price (Number)

4th Field: Dropdown: Name -> Approvers (to be dynamically populated)

When the user changes the values in any of the first three fields above, I execute a CAML query and populate the values in the Approvers dropdown field.

The query is woorking fine. However, when I submit the page I get a nasty 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.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: 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.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[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.]
   System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +8624793
   System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +72
   System.Web.UI.WebControls.DropDownList.LoadPostData(String postDataKey, NameValueCollection postCollection) +53
   System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +13
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +346
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1743

I know the error is cause of th view state of the Approvers dropdown.

I am trying to use the same technique as you did in the Cascade dropdown, but however, the posts are failing.

Can you shed some light on how I can fix the issue?

Any help would be appreciated.

Thanks

-Pritam

 

 

Coordinator
Aug 12, 2010 at 7:52 PM

Pritam:

Hard to tell. It sounds like you've written your own code.  The error indicates that you're trying to submit a value in the dropdown that isn't valid.

M.

Aug 17, 2010 at 5:56 PM

The Approvers dropdown is getting populated on the client side using jQuery.

My guess is that when the form gets submitted, the ASP.net viewstate for the dropdown is not matching since the original dropdown did not have any items in it 

and the postback now has items in it.

If this is true, I was wondering how your cascade dropdowns work as the items in the dropdown also change.

Coordinator
Aug 18, 2010 at 1:14 AM

Pritam,

It sounds to me like you're passing values in the postback that can't be validated. Are you setting valid values and such for your selects? Can you post code? It sounds to me like you've written something that breaks the SPServices/SP functionality, perhaps the "values" of your select fields don't reconcile with the list data, so SharePoint doesn't know what to do with it.

Mike

Aug 18, 2010 at 4:58 PM

Actually, this is the exact same issue that I was having when trying to create a custom form in .Net and then populate the dropdowns using javascript/jQuery. This always broke my .Net form and I could never get that part to play nicely.

There was just something about the viewstate of the form and the way it handles postbacks that it did not like being manipulated by client side code.

The only way I got this to work was to change the field type to text and to then to draw my own select boxes on the form using standard html and allow the jQuery code to populate that. Then I would apply a client side click event on that select that would use jQuery to populate that field. It seems like a hack, but works evertime.

I did this using custom rendering templates and by modifying the NewForm.aspx page for the list the form was for.

Coordinator
Aug 26, 2010 at 6:33 AM

pdahake:

SPCascadeDropdowns works because all of the possible values are present on page load. The function removes the values which aren't currently valid, but doesn't add any new values. I think that adding the new values is what's causing you the problem.

M.