I need to use visual web parts to create a new item form for a list. I know I can do this by using SSOM.. But I want to reduce the load on the server Can I use CSOM?.. Or is CSOM mainly for sandbox solution? Right now I am trying to write JavaScript code on ascx page but I am having issues with client context Please let me know if you have better ideas. I am working with sp2010 visual web parts. I do not want to use SharePoint designer and infopath Thanks in advance...

  • What do you do in this form "newform"? validation some fields? create more field and manipulate?
    – b1c10
    Dec 10, 2014 at 17:08
  • In my visual web part I have a asp drop down control which is binded with SharePoint list items. On change in JavaScript I need to get the selected text and using caml search the selected text in a different SharePoint list in which the selected text is a lookup column and display all such items..
    – Avinash
    Dec 10, 2014 at 17:12

1 Answer 1


There is a workaround to get the (C#) CSOM to work in a farm solution (the name for solutions that encompass code that needs to be installed on the server), there is an SP StackExchange answer on that here: CSOM in FarmSolution

You could also use a Sandbox solution as you mentioned; C# code in sandbox solutions is deprecated but you could create a webpart that used just the JavaScript Object Model (JSOM) to accomplish what you need. It's worth noting that you can create visual web parts in Sandbox solutions now as well.

As a final alternative, unless you need to leverage the webpart framework (passing values between web parts, or configuration properties) you could just create an HTML/CSS/JavaScript solution and implement it via source code on the aspx pages or something like the Content Editor Web Part -- this is the route that I currently use for light customization on SP2010.

For some more references on using the JSOM and JavaScript REST API see the following MSDN article on Javascript development in 2013 -- the vast majority of JSOM functionality is available in both versions, and 2010 supports ListData operations with REST:

  • Hi john, Thanks. But I have a requirement of fetching data from different list and displaying it on the web part.. Basically I have a drop down and once I select an option it should fetch data from a different list where the selected item in drop down will be a lookup.. I need to perform such functionalities.. Any suggestions?
    – Avinash
    Dec 10, 2014 at 17:27
  • Well my suggestion would be to do it client side and use the JSOM since it can easily accomplish everything you're describing; but if you're not comfortable in Javascript and can turn on the user code service in your environment I would suggest implementing a Sandbox Solution -- otherwise just leave everything Server Side in a farm solution (although that is the least preferred method for many reasons!)
    – John-M
    Dec 10, 2014 at 17:36
  • Yes, I am trying to use jsom but the code always gives me an error when I use get enumerator I get this error the collection has not been initialized it may not be requested or the request has not been executed. It may need to be explicit
    – Avinash
    Dec 10, 2014 at 17:44
  • Remember that Javascript code all executes asynchronously, you have to load the collection you want using context.load(clientObjectOrCollection) then use executeQueryAsync to retrieve the information and operate on it inside of a callback. I modified my answer a bit to provide a better JSOM reference, you can find list operation examples here: msdn.microsoft.com/en-us/library/office/…
    – John-M
    Dec 10, 2014 at 17:49
  • Yeah I have already done that.. I am not sure what the issue is..
    – Avinash
    Dec 10, 2014 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.