1
Reply

Write a Comment and tag to a friend

Mohammad Aman

Mohammad Aman

Dec 10 2016 2:22 AM
978
I am developing a social media site. their i have a option to comment on a post and that comment can tag also with a friend. I don't know how can do this code.
 I am trying to best to developer this but regret to do.
I am sharing my code with screenshot to better understanding for you guys :
 
1:  In this image, you will find to get user in  dropdown list with autocomplete
 
 
2: User choose name from . these name also contains profile link of itself. see second one
 
3: I am gonna show u final screenshot that make more understand about my doubt 
 
Here i am gonna show u my web method through them i am implementing my comment with autocomplete.
If you have any better or any other method to implement this please share with me
 
JavaScript Code:
 
f (CommentOnReviewText.indexOf("@") >= 0) {
var SubPart = CommentOnReviewText.split('@');
var prefix = SubPart[1];
if (prefix != "" && prefix != undefined && prefix != null) {
$('#CommentOnReview_' + ReviewId).autocomplete({
source: function (request, response) {
$.ajax({
url: VisitorPath + "Reviews.aspx/SearchUserNames",
data: "{ 'prefix': '" + prefix + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
//response(data.d);
response($.map(data.d, function (item) {
return {
label: item.split('$')[0],
val: item.split('$')[1]
}
}))
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
create: function (event, ui) {
$(this).data('ui-autocomplete')._renderItem = function (ul, item) {
debugger;
return $('<li>')
.append('<a href="' + VisitorPath + item.val + '" title="' + item.label + '">' + item.label + '</a>')
//.append('<a href="' + VisitorPath + item.label.split('$')[1] + '" title="' + item.label.split('$')[0] + '">' + item.label.split('$')[0] + '</a>')
.appendTo(ul);
};
},
//select: function (e, i) {
// //$("[id$=hfCustomerId]").val(i.item.val);
// //$('#CommentOnReview_' + ReviewId).val('<a href="' + VisitorPath + i.item.val.split('$')[1] + '" title="' + i.item.val.split('$')[0] + '">' + i.item.val.split('$')[0] + '</a>');
//},
minLength: 1
});
}
}
 
WebMethod: 
 
[WebMethod]
public static string[] SearchUserNames(string prefix)
{
List<string> customers = new List<string>();
DataTable dtNames = new DataTable();
ClientServiceClient ClientService = new ClientServiceClient();
dtNames = ClientService.SearchUserNames(prefix.TrimStart().TrimEnd()).Tables[0];
if (dtNames.Rows.Count > 0)
{
foreach (DataRow drw in dtNames.Rows)
customers.Add(string.Format("{0}${1}", drw["FullName"], drw["UserName"]));
}
return customers.ToArray();
}
 
 If anyone have better idea to implement this please share that method with
Thanks 
 

Answers (1)