This project has moved and is read-only. For the latest updates, please go here.

SPServices in "NewForm.aspx"

Jun 7, 2010 at 12:20 PM


I am trying to use SpServices in NewForm.aspx for one of my custom list.
I just want to get a "Title" of Projects list in the "Employees" list's Project dropdown & I should be able to save the item.

I always get this error while saving data.: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration

Cann't I do this using jQuery?
The following code I use to populate "Project" dropdown in Employees list. I can see items in Project dropdown but caanot save record back into the list.
Can you please help me in this?

<script type="text/javascript" src="../../Shared Documents/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../../Shared Documents/jquery.SPServices-0.5.4.js"></script>
<script type="text/javascript">

            CAMLViewFields:'<ViewFields><FieldRef Name="Title"/></ViewFields>',
            completefunc: function (xData, status)
                      var liHtml = "<option>" + $(this).attr("ows_Title") + "</option>";





Jun 7, 2010 at 7:00 PM


What type of field is your "Project" field? I'm assuming it's a select field based on the fact that you're adding options to it.

I think what's happening here is SharePoint is validating the submitted value against the list of possible choices configured in the field itself and finding that it's not a choice. So it's failing validation on submit. Your code looks right, so I'm thinking it's something on the SharePoint end.

I have tried to do something like what you're doing, but I had to take a different approach and use a text field instead of a choice field. You may try what I did, which was to use jQuery to add your own row to the form above the text field, write your own select into that row that contains all of the options, and write a line of code to set the value of the text input to the value of the select anytime the select is changed. Then you can use jQuery to hide the row containing the real text input. The text input is then the catalyst to submit the data, but the user never sees it (as they interact with your select instead).


Jun 8, 2010 at 7:09 AM

Thanks Mike!

This was helpful.
If this is how jQuery works then I'll have to think this way.

I know if we are updating control on client side, ASP.NET will not understand this but in case of SPCascadeDropdown does this kind of functionality without writing any javascript.
How does that handle the required values?


Jun 8, 2010 at 12:44 PM


This isn't a "way jQuery works" thing, I don't think. If the Project column is a lookup to another list, then you won't get away with adding values which aren't in that list.  However, I don't *think* that error is being caused by your addition.  The error is complaiinng about your event validation setting in web.config. SPServices ought not to have anything to do with that.

Since I'm here, a couple of notes on your script:

  • <script type="text/javascript" src="../../Shared Documents/jquery.SPServices-0.5.4.js"></script> --> Use the minified version once you get things up and running.
  • $(xData.responseXML).find("z\\:row") --> See my blog post on this. Better to use $(xData.responseXML).find("[nodeName=z:row]")

And finally, is there some reason you aren't just making the Project column in Enmployees a Lookup column to the Title in Projects?


Jun 8, 2010 at 1:46 PM

Thanks Mark!

The reason I am not using Lookup field is that eventually, I want to put the "Projects" list in my parent site (top level site).
As a first step, I just tried putting Projects list in the same site.

And in web.config, I have not made any changes.
<pages enableSessionState="false" enableViewState="true" enableViewStateMac="true" validateRequest="false" ...>

And yes, I'll go though the link you have given.



Jun 8, 2010 at 1:58 PM
Edited Jun 8, 2010 at 2:24 PM

If Project isn't a lookup, is it a dropdown?  Same thing applies: you can't add new values directly to the page that don't exist in the choices for the column.

You might also want to look at the SPAutocomplete function.


Jun 8, 2010 at 2:56 PM

Ok Mark. got your point!
Will have look at SPAutocomplete function.

Thanks for your help.