I have tried using a public function, but I must have the syntax wrong. I get no error - it just does not work (I have tested the function - it works).
Thanks for your help. I saw that you can't have two sets of double-quotes, so I made the outer ones single.
This worked in my test page, but not when implemented into an existing page.
GetLocalString is a Public function that goes out to a dll to get resources. I tested it by itself and it works. When in debug, it seems it is not being called. Any idea why that might be?
Thanks for your help. I saw that you can't have two sets of double-quotes, so I made the outer ones single.
1. Inside server code (b/w <% %>) you can(must) write in double quotes, as single quote would mean a char variable and we can't pass a string as a char type as per C# syntax.
2. Since you've written an extension method, you should be able to call it with string.ToLocalString(""), that will save you from writing another function and calling it.
Thank you for your suggestions. It seems <% MyFunction %> does not work within the Text="..." property of any control. It does work otherwise. I was hoping for a more generic solution because the need exists for other controls, as well.
Is your label inside a gridview or some other control? A more generic solution would be to write a custom resource writer or creating custom controls as I suggested above.
Saavik
Member
467 Points
457 Posts
Is it possible to localize a string where the source is in dll?
Sep 22, 2011 04:43 AM|LINK
I would like to localize .aspx, where instead of finding the resources in App_GlobalResources.dll, the resources could be found in another dll.
Normally, to specify resources in App_GlobalResources.dll, the syntax is:
<%$Resources:MyResources, String1 %>
If it is possible, how would the syntax change?
Help is most appreciated.
================
Saavik
shashankgwl
All-Star
18926 Points
3662 Posts
Re: Is it possible to localize a string where the source is in dll?
Sep 22, 2011 04:56 AM|LINK
I can think of writing an extension method "ToLocalizedString" for string class which will get the data from the dll and return a localized string.
All is well if it runs well.
blog
Saavik
Member
467 Points
457 Posts
Re: Is it possible to localize a string where the source is in dll?
Sep 23, 2011 02:43 AM|LINK
I have created such a method - can this method be used in .aspx declarations? How?
================
Saavik
shashankgwl
All-Star
18926 Points
3662 Posts
Re: Is it possible to localize a string where the source is in dll?
Sep 23, 2011 04:50 AM|LINK
Any public/protected function property can be accessed from aspx.
All is well if it runs well.
blog
Saavik
Member
467 Points
457 Posts
Re: Is it possible to localize a string where the source is in dll?
Sep 23, 2011 05:12 PM|LINK
I have tried using a public function, but I must have the syntax wrong. I get no error - it just does not work (I have tested the function - it works).
Here is an example of the syntax I tried:
<asp:Label ID="Label1" runat="server" Text="<%= GetLocalString('ResourceName') %>"></asp:Label>
What's wrong with it?
Help most appreciated.
================
Saavik
shashankgwl
All-Star
18926 Points
3662 Posts
Re: Is it possible to localize a string where the source is in dll?
Sep 24, 2011 11:49 AM|LINK
it should be GetLocalString("ResourceName")
also what is the definition of GetLocalString
All is well if it runs well.
blog
Saavik
Member
467 Points
457 Posts
Re: Is it possible to localize a string where the source is in dll?
Sep 25, 2011 02:05 AM|LINK
Thanks for your help. I saw that you can't have two sets of double-quotes, so I made the outer ones single.
This worked in my test page, but not when implemented into an existing page.
GetLocalString is a Public function that goes out to a dll to get resources. I tested it by itself and it works. When in debug, it seems it is not being called. Any idea why that might be?
================
Saavik
shashankgwl
All-Star
18926 Points
3662 Posts
Re: Is it possible to localize a string where the source is in dll?
Sep 25, 2011 02:42 AM|LINK
1. Inside server code (b/w <% %>) you can(must) write in double quotes, as single quote would mean a char variable and we can't pass a string as a char type as per C# syntax.
2. Since you've written an extension method, you should be able to call it with string.ToLocalString(""), that will save you from writing another function and calling it.
SO
<asp:Label runat="server" id="Label1" Text='<%=string.ToLocalString("ResourceName")%>' />should work.
3. I would either create a custom resource provider (as shown here) or create custom control with overridden text property
public class CustomLabel : Label { public CustomLabel() : base() { } public string ResourceKey { get { return ViewState["ResourceKey"].ToString(); } set { ViewState["ResourceKey"] = value; } } public override string Text { get { return string.ToLocalizedString(ResourceKey); } set { base.Text = value; } } protected override void Render(System.Web.UI.HtmlTextWriter writer) { base.Render(writer); } }All is well if it runs well.
blog
Saavik
Member
467 Points
457 Posts
Re: Is it possible to localize a string where the source is in dll?
Sep 25, 2011 01:25 PM|LINK
Thank you for your suggestions. It seems <% MyFunction %> does not work within the Text="..." property of any control. It does work otherwise. I was hoping for a more generic solution because the need exists for other controls, as well.
Much appreciated.
================
Saavik
shashankgwl
All-Star
18926 Points
3662 Posts
Re: Is it possible to localize a string where the source is in dll?
Sep 25, 2011 03:57 PM|LINK
All is well if it runs well.
blog