简体   繁体   中英

Localize text using Resources on Asp.Net WebForms in javascript

I have ASP.NET WebForms application c# based.

I have ImageButton

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

Problem: dont show resource value but show '<%$Resources:Resource, Confirm%>'

Resources:Resource.Confirm = 'Are you sure to delete this item?'

how to show resource key value?

please use:

1-in page code behind c#:

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

edit ImageButton:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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