Thursday, 18 September 2014

Programmatically Save the items into SharePoint List by using SPServices

For this code we have to  include Jquery mini file and SPServices file from http://jquery.com/download/
function btnSaveClick(){
 try
 {
 var FirstName= $("#txtfirstname").val();
 var LastName=$("#txtlastname").val();
 var Location=$("#txtlocation").val();

 $().SPServices({
 operation: "UpdateListItems",
 async: false,
 batchCmd: "New",
 listName: "Registration",
 valuepairs: [["col_FirstName",FirstName],["col_LastName",LastName],["col_location",Location]],
 completefunc: function (xData, Status) {

 alert("Succefuly save items into SPList");
 window.frameElement.commitPopup();

 }
 });
 }

 catch (ex) {
 alert('error:' + ex.Message);
 }
 }


Here col_FirstName,col_LastName and col_loaction  are created  list columns
The Bellow Code is Html

<div class="innercontent1">
<div class="Outer">
<asp:Label ID="lblFirstname" runat="server" Text="First Name"></asp:Label>
</div>
<div>
<asp:TextBox ID="txtfirstname" runat="server"></asp:TextBox>
</div>
</div>

<div class="innercontent1">
<div class="Outer">
<asp:Label ID="lblLastname" runat="server" Text="Last Name"></asp:Label>
</div>
<div>
<asp:TextBox ID="txtlastname" runat="server"></asp:TextBox>
</div>
</div>
<div class="innercontent1">
<div class="Outer">
<asp:Label ID="Lbllocation" runat="server" Text="Lcation"></asp:Label>
</div>
<div>
<asp:TextBox ID="txtlocation" runat="server"></asp:TextBox>
</div>
</div>
<div class="innercontent1">
<div>
<asp:Button ID="btnSave"  runat="server" Text="Save" OnClientClick="return btnSaveClick();" />
</div>
</div>

Regards
Tharak
Happy Coding

No comments:

Post a Comment