0

I am sending some parameters to a c# webmethod with ajax from an aspx page. I have had to encode the comments and use a replace to remove the apostrophes as i just could not find a way to remove the apostrophes any other way. As an experiment i added a load of characters such as $&%', etc to make sure they are being dealt with and they are. when bringing the comments back in the gvPSTNResults_RowDataBound() event i have written some code to decode it and it before it goes back in to the gridview and it does not seem to work.

The contents of the comment cell looks like this (between the xxx's should be characters like &$% etc), but as you can see they are not decoding :bbbbaaaaa'xxx%40xxx~xxx%24xxx%26xxx%2Cxxx%3Fxx

Any advice would be appreciated

The C# to decode the comments coming back from the database:

Label lblComments = new Label();
lblComments = (Label)e.Row.FindControl("lblComments");
string strComments = lblComments.Text;
strComments = System.Net.WebUtility.HtmlDecode(strComments);
lblComments.Text = strComments;

The Jquery Ajax:

$("#btnEditFields").click(function () {
var strSupplierOrderNo = $("#<%=tbPopUpEditSuppOrdNo.ClientID%>").val();
var strComment = $("#<%=tbPopUpEditComments.ClientID%>").val();
strComment = encodeURIComponent(strComment);
strComment = strComment.replace(/'/g,"\\'");
var strCurrentStage = $("#<%=ddlPopUpEditCurrentStage.ClientID%>").val();
var strReviewDate = $("#<%=tbPopUpEditReviewDate.ClientID%>").val();
var strOrderDate = $("#<%=tbPopUpEditOrderDate.ClientID%>").val();
var strRequiredLive = $("#<%=tbPopUpEditRequiredLiveDate.ClientID%>").val();
var strActualAppointmentDate = $("#<%=tbPopUpEditActualAppointmentDate.ClientID%>").val();
var strOtherRef = $("#<%=tbPopUpFieldOtherRef.ClientID%>").val();
if (confirm("You are about to add a new comment to order " + strPSTNNum + "?")) {
$.ajax({
type: "POST",
url: "PSTN_OrderManagementTracker.aspx/updatePSTNDataInDB",
data: "{'args':'" +strServiceID+ "', 'args1':'" +strSupplierOrderNo+ "', 'args2':'" +strComment+ "', 'args3':'" +strCurrentStage+ "', 'args4':'" +strReviewDate+ "', 'args5':'" +strOrderDate+ "', 'args6':'" +strRequiredLive+ "', 'args7':'" +strActualAppointmentDate+ "', 'args8':'" +strOtherRef+ "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () {
alert("Comment successfully added!!!");
location.reload();
},
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
});
}
return false;
});
});
4

1 回答 1

0

尝试使用Uri.UnescapeDataString()

于 2013-05-23T12:35:54.660 回答