Reputation: 127
If user hits show comments button with class comments, pop up opens up. Want to populate this pop up (gridview is content of the pop up) with comments for the Item. html :
<div class="pop-up-comments">
<div class="pop-up-wrap-comments">
<div class="edit-form">
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField DataField="CommentText" HeaderText="CommentText" />
<asp:BoundField DataField="Date" HeaderText="Date" />
</Columns>
</asp:GridView>
</div>
<div class="user-controls">
<button class="close-popup btn btn-danger">Close</button>
</div>
</div>
</div>
js
$(document).on("click", ".comments", function () {
var clicked = $(this);
var id = clicked.attr("data-id");
alert(id);
$.ajax({
type: "POST",
url: "Admin.aspx/ShowComments",
data: id,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
var returnedstring = data.d;
alert(returnedstring);
}
});
$('.pop-up-comments').addClass('show-popup');
});
c#
[WebMethod]
public static string ShowComments(string id)
{
return id;
}
Breakpoint on this WebMethod never fires. Why ? And how to send array of comments into datagridview ??
Upvotes: 0
Views: 352
Reputation: 34834
ASP.NET AJAX Page Methods accept and return JSON, so you need to convert the data you are sending to JSON via JSON.stringify
, like this:
$(document).on("click", ".comments", function () {
var clicked = $(this);
var id = clicked.attr("data-id");
alert(id);
var dataToSend = {
id: id
};
$.ajax({
type: "POST",
url: "Admin.aspx/ShowComments",
data: JSON.stringify(dataToSend),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
var returnedstring = data.d;
alert(returnedstring);
}
});
$('.pop-up-comments').addClass('show-popup');
});
Upvotes: 1