Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 716
Meysam Chegini Avatar asked Jun 21 '26 15:06

Meysam Chegini


1 Answers

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)')"/>
like image 73
Meysam Chegini Avatar answered Jun 23 '26 06:06

Meysam Chegini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!