简体   繁体   English

HtmlDecode()似乎不起作用

[英]HtmlDecode() does not appear to be working

I am sending some parameters to ac# webmethod with ajax from an aspx page. 我正在从apxx页面使用ajax向ac#webmethod发送一些参数。 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. 当在gvPSTNResults_RowDataBound()事件中带回评论时,我写了一些代码对其进行解码,然后将其返回到gridview,它似乎不起作用。

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 注释单元格的内容看起来像这样(在xxx之间应该是&$%等字符),但是您可以看到它们没有在解码:bbbbaaaaa'xxx%40xxx〜xxx%24xxx%26xxx%2Cxxx%3Fxx

Any advice would be appreciated 任何意见,将不胜感激

The C# to decode the comments coming back from the database: C#解码从数据库返回的注释:

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: 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;
});
});

尝试使用Uri.UnescapeDataString()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM