Hi nauna,
Refer below sample.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/json2/0.1/json2.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=LinkButton1]").bind("click", function () {
var username = '<%=@HttpContext.Current.User.Identity.Name%>';
var projectid = createGuid();
$.ajax({
type: "POST",
url: "Default.aspx/insertbid",
data: "{username: '" + username + "', projectid: '" + projectid + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) { alert(response.responseText); }
});
return false;
});
});
function createGuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
</script>
<asp:LinkButton ID="LinkButton1" runat="server">Submit</asp:LinkButton>
</form>
</body>
</html>
Namespaces
using System.Web.Services;
Code
[WebMethod]
public static string insertbid(string username, Guid projectid)
{
if (!string.IsNullOrEmpty(username))
{
string getuser = username;
}
return string.Format("{0},{1}", username, projectid);
}
You need to generate guid refer below link to generate guid.
https://www.c-sharpcorner.com/blogs/generate-guid-using-javascript1