Hi nauna,
Check this sample. now take its reference.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
function InsertImageUrl() {
var imgArray = new Array();
var obj = {};
var imgUrl = $('[id*=divImages]').find('img');
$.each(imgUrl, function () {
debugger;
var singleUrl = $(this).attr('src')
obj.Url = singleUrl;
imgArray.push(obj);
});
$.ajax({
type: "POST",
url: "Default.aspx/InsertImageUrl",
data: JSON.stringify({ urls: imgArray }),
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (response) {
},
error: function (response) {
alert(response.responseText);
}
});
}
</script>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnSubmit" Text="Insert ImageUrl" runat="server" OnClientClick="InsertImageUrl();" />
<div id="divImages">
<img src="http://ae01.alicdn.com/kf/HTB1agZyaOYrK1Rjy0Fdq6ACvVXao.jpg" />
<img src="https://ae01.alicdn.com/kf/HTB19mIWhXzqK1RjSZFCq6zbxVXaR.jpg" />
<img src="https://ae01.alicdn.com/kf/HTB19AdnXvvsK1Rjy0Fiq6zwtXXaF.jpg" />
<img src="https://ae01.alicdn.com/kf/HTB1RhoWhgTqK1RjSZPhq6xfOFXaa.jpg" />
<img src="https://ae01.alicdn.com/kf/HTB1gsXnXyLrK1Rjy1zdq6ynnpXat.jpg" />
<img src="https://ae01.alicdn.com/kf/HTB1SHMZhcfpK1RjSZFOq6y6nFXaN.jpg" />
<img src="https://ae01.alicdn.com/kf/HTB1UCFmXzDuK1Rjy1zjq6zraFXao.jpg" />
<img src="https://ae01.alicdn.com/kf/HTB1FuhehxnaK1RjSZFBq6AW7VXaP.jpg" />
<img src="https://ae01.alicdn.com/kf/HTB1YJBlXvLsK1Rjy0Fbq6xSEXXa3.jpg" />
<img src="https://ae01.alicdn.com/kf/HTB1KfpihyLaK1RjSZFxq6ymPFXaW.jpg" />
<img src="https://ae01.alicdn.com/kf/HTB1BphmXyfrK1RjSspbq6A4pFXaA.jpg" />
<img src="https://ae01.alicdn.com/kf/HTB111hmXsfrK1RkSmLyq6xGApXaQ.jpg" />
<img src="https://ae01.alicdn.com/kf/HTB1FItnXyLrK1Rjy1zdq6ynnpXaR.jpg" />
</div>
</div>
</form>
</body>
</html>
Namespaces
C#
using System.Configuration;
using System.Data.SqlClient;
using System.Web.Services;
VB.Net
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Web.Services
Code
C#
[WebMethod]
public static string InsertImageUrl(List<Imgurl> urls)
{
foreach (Imgurl imgurl in urls)
{
// Write code to insert in database.
string constr = ConfigurationManager.ConnectionStrings["Constring"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
string query = "INSERT INTO URLS VALUES (@Url)";
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
con.Open();
cmd.Parameters.AddWithValue("@Url", imgurl.Url);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
return "";
}
public class Imgurl
{
public String Url { get; set; }
}
VB.Net
<WebMethod>
Public Shared Function InsertImageUrl(ByVal urls As List(Of Imgurl)) As String
For Each imgurl As Imgurl In urls
Dim constr As String = ConfigurationManager.ConnectionStrings("Constring").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Dim query As String = "INSERT INTO URLS VALUES (@Url)"
Using cmd As SqlCommand = New SqlCommand(query)
cmd.Connection = con
con.Open()
cmd.Parameters.AddWithValue("@Url", imgurl.Url)
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
Next
Return ""
End Function
Public Class Imgurl
Public Property Url As String
End Class