3

我有基于 c# 的 ASP.NET WebForms 应用程序。

我有图像按钮

<asp:ImageButton ID="divSection_btnAdd" runat="server" 
OnClientClick="return  TConfirm(this,'<%$Resources:Resource, Confirm%>')"/>

问题: 不显示资源值但显示 '<%$Resources:Resource, Confirm%>'

Resources:Resource.Confirm = '你确定要删除这个项目吗?'

如何显示资源键值?

4

1 回答 1

2

请用 :

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)')"/>
于 2019-10-21T12:49:26.817 回答