The rear end to the front page of a method of transmitting a variable may contain special characters (e.g., double quotation marks)

Variable transmission to the rear end of the front page, if the variable has no special characters, such as English double quotes and the like may be used as the front end

var value = "<% = this.IsHuaMedicineAlertMsg.ToString (). ToLower ()%>" in this manner is supplied to the front end,

However, if the variable has special characters, such as English double quotes (usually some html fragments may contain style and so there will be double quotation marks), you can not use the above method,

In this case it is necessary to back the sequence number of characters used and threw the front end, so that they do not write the code received at the front end of the rear end of the variable,

This principle is possible because the special character of the serial number will be special treatment, so reception can be received normally.

details as follows:

rear end:

/ KeyName with the contents to find the companies in a single resource file, and then converted into json thrown reception, because contents to be html fragments may involve double quotes, etc., it is necessary to turn json
var KeyName = EAPConsts.GetCompanyParameter (group companyID, 385);
var = ALERTMSG TCG.ESOP.Resources.MessageResource.ResourceManager.GetString (PlaceOrderAlertMsgKeyName);
Page.ClientScript.RegisterClientScriptBlock (this.GetType (), "XXXX", $ "= {Newtonsoft.Json window.AlertContent .JsonConvert.SerializeObject (AlertMsg)}; ", true);

Distal directly window.AlertContent like, such as:

var msg = window.AlertContent;

备注:Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "xxxx", $"window.AlertContent={Newtonsoft.Json.JsonConvert.SerializeObject(AlertMsg)};", true);

和Response.Write($"<script type='text/javascript'>window.AlertContent={Newtonsoft.Json.JsonConvert.SerializeObject(AlertMsg)};</script>");是等效的。

 

Guess you like

Origin www.cnblogs.com/itjeff/p/10972743.html