asp.net metaresource key failed to take value on resx file - asp.net

I am currently building a project with localization. I work on some .aspx files and i "localize" all the strings in it. Firstly i go to .aspx file on Design View. Then Tools->Generate Local Resource. This builds a .resx file with most of the strings and their values automatically.
When i find a string like this:
<ItemTemplate>
Κατάσταση:
Κατάσταση==Situation on Greek. I mark "Κατάσταση" and i use resharper (Alt+enter => MoveHtmlToResource) and it generates a row on the .resx file with value "Κατάσταση" and the name that i typed.
My problem is on something like that:
<asp:Button ID="SituationButton" runat="server" CommandName="Situation" Text="Κατάσταση" />
There is no metaresource key attribute and the resharper does nothing here. When i try to type manually the metaresourcekey like this:
<asp:Button ID="SituationButton" runat="server" CommandName="Situation" Text="Κατάσταση" meta:resourcekey="Situation"/>
it creates a new row on the .resx file with name="Situation" and the value="Situation". The value should be "Κατάσταση".
The purpose of this is to built a multiple language web site.
Any ideas?
Thank you

The problem solved like this:
<asp:Button ID="SituationButton" runat="server" CommandName="Situation" Text="Κατάσταση" meta:resourcekey="Situation"/>
Then you change manually the .resx file value from "Situation" to "Κατάσταση"

Related

Expression to catch Single Quote & Special Characters using ValidationExpression in ASP.NET

I am working on the asp.net webpage and in the FileUpload control, I am using the ValidationExpression to detect if the selected file has the needed image extension or not. So far it is working fine but I am struggling to detect Single Quote or Special characters in the file name selected by the user with-in the same expression. The idea is to refrain user to use the special characters.
The current code is
<asp:RegularExpressionValidator
runat="server" ID="ImageUpload_TypeValidation"
ControlToValidate="txt_CategoryPicture" Display="Dynamic"
ErrorMessage="Only files with extension JPG/JPEG/GIF/PNG/TIF/BMP are allowed."
SetFocusOnError="true" ValidationGroup="AddNewCategory"
ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.jpg|.JPG|.png|.PNG|.jpeg|.JPEG|.gif|.GIF|.tif|.TIF|.bmp|.BMP)$">
</asp:RegularExpressionValidator>
Appreciate.
Can you please check and verify this regex.
^.*[\w\s].*[a-zA-Z0-9_#.-]*[\w\s].*(.jpg|.JPG|.png|.PNG|.jpeg|.JPEG|.gif|.GIF|.tif|.TIF|.bmp|.BMP)$
I opted to generate the unique file name for every file upload using Microsoft's inbuilt function of GUID.NewGUID() and converting the image files to .png type. This eliminates any special characters that I didn't want user to have as a filename. Another benefit is that the system will always get the unique file name.
strUploadedFileName = Guid.NewGuid().ToString() & ".png"

Print a Resources.resx file value within ASP.NET tags

I'm required to print a value of a string which within a resource files (.resx) within asp.net tags
i used the following approaches
for example :
<ext:ComboBox ID="cmbProgram" runat="server" FieldLabel="<%= Resource.StringName %>"
<ext:ComboBox ID="cmbProgram" runat="server" FieldLabel="<%= Response.Write(Resource.StringName) %>"
But both approaches didin't provide the value of the string, but provides the ID. How to get the values within the ASP.NET tags?
Assuming you have Control.ascx:
<ext:Tag runat="server" meta:resourcekey="fooBar" />
Then put Controls.ascx.resx in App_LocalResources containing appropriate strings:
fooBar.PropetyName = "x"

asp.net: using resource expressions with the resources in a separate project

I'm pretty sure this is something super easy, but how do i access a resource that is in a separate project using the expression syntax?
I thought it would be like so:
<%$ Resources:SomeNamespace.Resources.Web, PleaseSelectAnImage %>
where SomeNamespace.Resources is the project that the resources are located in.
i normally just do <%= SomeNamespace.Resources.Web.PleaseSelectAnImage%> but i need to have this inside a control.
<kw:SlickUpload ID="SlickUpload1" runat="server"
ValidExtensions=".png, .gif, .jpg"
InvalidExtensionMessage="<%$ Resources:SomeNamespace.Resources.Resources.Web, PleaseSelectAnImage %>" >
so when i just do what i normally do, it puts
'<%= SomeNamespace.Resources.Web.PleaseSelectAnImage%>" literally.
my project name is SomeNamespace.Resources. the resource file name is Web. and the key is PleaseSelectAnImage.
Patricia, you'll need to implement a custom ResourceProviderFactory and corresponding IResourceProvider in order to do this. Some good reference can be found here.

ASP.NET: two ways to access global resource programmatically

I know that I can set a Label's text by using the following syntax.
lblMessage.Text = (string)GetGlobalResourceObject("resxFile", "message");
What are the benefits and drawbacks associated with using the below syntax?
lblMessage.Text = Resources.resxFile.message;
The second method will not work for local resource files. Is there a different syntax for local resource files?
The second way looks better because it is strongly-typed. If you changed the resource file name or the resource value name then you would get a compile error. If you needed to dynamically get a resource, then you would have to do it the first way, else use a switch statement or something similar.
If you are using asp.net 2.0 or higher there is actually a 3rd way to set a label by using markup only:
<asp:Label ID="Label1" runat="server" Text="<%$ Resources:resxFile,message %>" />
Kinda related to localization: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/localization/localization.aspx

Validation controls error message from Resource file and parameterized

I would like to get validation messages for validation controls from resource files. I know I can do that easily by following code snippet.
<%$ Resources:[filename prefix,]resource-key %>
or
<asp:Label ID="Label1" runat="server" meta:resourcekey="resource-key-prefix" />
But I would also like to parameterized it.
e.g.
Above Resource Expression will give me message like "Fill Information.". What I have in resource file is "Fill {0} Information." which should show end user message like "Fill Address Information.".
So basically you want to have a localized Formatstring.
You can access the resource file from the codebehind, perform a String.Format and pass the value on to a control.
E.g.
myLabel.Text = string.Format(ProjectnameSpace.Resources.xxy, VALUE);
Try intellisense to get the full path of the property, I don't have visual studio here atm

Resources