javascript - 在 JavaScript 中使用 Asp.Net WebForms 上的资源本地化文本
问题描述
我有基于 c# 的 ASP.NET WebForms 应用程序。
我有图像按钮
<asp:ImageButton ID="divSection_btnAdd" runat="server"
OnClientClick="return TConfirm(this,'<%$Resources:Resource, Confirm%>')"/>
问题: 不显示资源值但显示 '<%$Resources:Resource, Confirm%>'
Resources:Resource.Confirm = '你确定要删除这个项目吗?'
如何显示资源键值?
解决方案
请用 :
c# 后面的 1-in 页面代码:
protected override void Render(HtmlTextWriter writer)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hWriter = new HtmlTextWriter(sw);
base.Render(hWriter);
writer.Write(this.Localize(sb.ToString()));
}
private const string ResourceFileName = "Resource";
private string Localize(string html)
{
MatchCollection matches = new Regex(@"Localize\(([^\))]*)\)", RegexOptions.Singleline | RegexOptions.Compiled).Matches(html);
foreach (System.Text.RegularExpressions.Match match in matches)
{
html = html.Replace(match.Value, GetGlobalResourceObject(ResourceFileName, match.Groups[1].Value).ToString());
}
return html;
}
编辑图像按钮:
<asp:ImageButton
ID="divSection_btnAdd"
runat="server"
OnClientClick="return TConfirm(this,'Localize(Confirm)')"/>
推荐阅读
- javascript - 如何在默认情况下禁用按钮并在页面完全加载时启用它?
- tensorflow - efficientnet.tfkeras 与 tf.keras.applications.efficientnet
- clickhouse - 为什么修改表格列clickhouse时出现错误
- c# - wix卸载对话框中的错字
- go - 推迟到函数外
- r - R:根据列表元素名称创建新的数据框变量
- r - 根据上限向数据框添加新列
- asp.net - IIS Express 信任自签名 SSL 证书按下否
- javascript - 如何在 JavaScript 中将对象数组(动态)转换为对象
- sql-server - SSRS - 根据查询中返回的值重复一个矩形