locked
Localisation in javascript on code behind RRS feed

  • Question

  • User-780288965 posted

    Hi,

    I am trying to show a pop up message using java script from code behind. It works fine when the alert message is included in the code. But not able to access the value from the resource file. The above works fine but when I try to access the resorce file key in the alert message, it does not work.

    Works Fine:

                    String csName = "ButtonClickScript";
                    Type csType = this.GetType();
    
                    ClientScriptManager cs = Page.ClientScript;
    
                    if (!cs.IsClientScriptBlockRegistered(csType, csName))
                    {
                       
                        cs.RegisterStartupScript(csType, csName, "<script language='javascript'>alert('No results Returned');</script>");


    But this does not work:

    cs.RegisterStartupScript(csType, csName, "<script language='javascript'>alert('<%=GetGlobalResourceObject(/"ResxfileName/",/"KeyName/") %>');</script>");

    I also tried assiging the value to a string and then tried to access it but it did not work.

    Could someone help please.

    Thanks,
    Sathish

    Tuesday, November 22, 2011 11:42 AM

Answers

  • User-99544339 posted

    Have you tried something like this?

    string message = GetGlobalResourceObject("ResxfileName","KeyName"); 
    
    string script = String.Format( "<script language='javascript'>alert('{0}');</script>", message);
    
    cs.RegisterStartupScript(csType, csName, script);

    Or you can look at the Localizing Resources for Component Libraries http://msdn.microsoft.com/en-us/library/bb398937.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 22, 2011 4:08 PM

All replies

  • User-99544339 posted

    Have you tried something like this?

    string message = GetGlobalResourceObject("ResxfileName","KeyName"); 
    
    string script = String.Format( "<script language='javascript'>alert('{0}');</script>", message);
    
    cs.RegisterStartupScript(csType, csName, script);

    Or you can look at the Localizing Resources for Component Libraries http://msdn.microsoft.com/en-us/library/bb398937.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 22, 2011 4:08 PM
  • User-780288965 posted

    Thanks Erwin, it worked :)

    Wednesday, November 23, 2011 10:04 AM