.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Post New Resource Bookmark and Share   

Create Custom list : ECMA Script Client Object Model.

Posted By:Sagar Pardeshi       Posted Date: October 23, 2013    Points: 25    Category:    URL: http://www.dotnetspark.com  

Create Custom list using Client Object model
 

<input type="text" id="txtLst" />
<input type="button" id="btnAdd" onclick="CreateList();" value="Create Custom List" />
<label id ="lbl" runat="server"/>

<Sharepoint:ScriptLink name="SP.js" runat="server" OnDemand="true" localizable="false"/>

<script type="text/ecmascript">

function CreateList()
{
  

var txtLstName = document.getElementById("txtLst");
if (txtLstName.value == "") {
alert("please enter");
return;
}

    var clientContext = new SP.ClientContext(); 
    var oWebsite = clientContext.get_web(); 
    var listCreationInfo = new SP.ListCreationInformation(); 
    listCreationInfo.set_title(txtLstName); 
    listCreationInfo.set_templateType(SP.ListTemplateType.GenericList); 
    listCreationInfo.set_quickLaunchOption(SP.QuickLaunchOptions.on); 
    this.oList = oWebsite.get_lists().add(listCreationInfo); 
    var itemCreateInfo = new SP.ListItemCreationInformation(); 
    this.oListItem = oList.addItem(itemCreateInfo); 
    oListItem.set_item('Title', 'Example item for ' ,'test100'); 
    oListItem.update(); 
    clientContext.load(oListItem); 
    clientContext.load(oList); 
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); 
}

function onQuerySucceeded()
{ 
    alert("Succeeded");
} 
function onQueryFailed(sender, args)
{ 
    alert("fail");
} 
</script>


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend