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.
Related
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 "Κατάσταση"
I have project asp.net with namespace test and I'm using resources (files Resource.resx and Resource.en-GB.resx). I have in resources key MY_TEXT with value. In file .aspx I can use
<%# Resources.Resource.MY_TEXT %>
but when I'm using (like in article http://msdn.microsoft.com/en-us/magazine/cc163566.aspx)
myLabel.Text = Resource.MYTEXT;
It don't found it and I have build error. Why?
Best regards,
Dagna
Try something like this:
myLabel.Text = Resources.Resource.MYTEXT;
Let me know if it works or what kind of error the compiler gives you.
You can also write it as you wrote in your question, click on Resources to put cursor there, hit Ctrl + . and select a namespace to be added. This should make Visual Studio detect a valid Resource namespace (or suggest few available namespaces) automatically.
Update
This article explains how to use resources in code behind:
http://msdn.microsoft.com/en-us/library/ms227982%28v=vs.85%29.aspx. I mentioned it in comments and it helped you, so I'm adding it as a part of an answer.
You can get a text from resources using some methods in aspx.cs file.
For local resources:
myLabel.Text = GetLocalResourceObject("MYTEXT").ToString();
For global resources:
myLabel.Text = GetGlobalResourceObject("MYTEXT").ToString();
For more information visit: https://msdn.microsoft.com/en-us/library/ms227982%28v=vs.140%29.aspx
I'm trying to make the switch from Java to .NET.
I've noticed a number of ASP.NET pages have <%$ sometext %> in them. Can someone explain what this does in a couple of sentences, or point me to a reference on the syntax?
It's expression builder syntax, and it's used commonly to access settings in the web.config. Here's an example using expression builder syntax to get a connection string:
ConnectionString="<%$ ConnectionStrings:sqlconnection %>"
Here's a good article that explains all of the inline expressions:
http://support.microsoft.com/kb/976112
The expression builder is used to set values of control properties based on the information that is contained in an application's configuration or resource files. The following is the basic syntax of the expression builder:
<%$ Expression Prefix: Expression Value %>
The dollar sign ($) indicates to ASP.NET that the following expression is an expression builder. The expression prefix defines the kind of expression, such as AppSettings, ConnectionStrings, or Resources. Additionally, you can create and define your own expression builder. The expression value that follows the colon (:) is what ASP.NET will actually use as the value of a certain property.
It references what is called an "Expression Builder". It's just a component that can plug into the parsing mechanism. The expression builder is fed the content of the expression, and it is responsible for returning CodeDOM expressions that describe how to get the actual value.
I've implemented a generic expression builder that lets you put any code in it:
http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx
It's inline codebehind.
Here's a link to some more info
http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx
<%$ expressionPrefix: expressionValue %> is used for expressions. Where the expressionPrefix is the expression builder it uses, and the expressionValue is the actual expression that gets passed to the expression builder.
An example usage: <%$ AppSettings: greeting %> which would read out the greeting from the application configuration. Various expression builders are supplied by default such as:
AppSettings
Resources
ConnectionStrings
It is also possible to create your own custom expression builder(s).
This page gives a nice overview of various available ASP.NET tags. Although it is missing <%: %> which HTML encodes the supplied contents.
It is called expression and is used for various things including reading from web.config, app settings and resource files for localizations. Resource expressions are probably the most used form of expressions. Instead of putting the static text in the controls, this expression can be used and the ASP.NET runtime would pick the resource file for the current culture and extract the value from it.
I'm new to ASP, VBScript and am trying to figure out how to change some text on a webpage.
What I want to do:
Change some text in a web page
The problem:
The web page (.asp) text seems to be generated by code that looks like this: <% Set MyAd = Server.CreateObject("ETFramework11.WPLoginPage") %> and I cannot directly see the text that I want to change.
Question:
Where does the file(s) housing the ETFramework11 or WPLoginPage reside physically? (assuming that they reside in separate files somewhere) What are the file types? What do they look like?
CreateObject is used to instantiate a COM object. So ETFramework11.WPLoginPage is an object in a DLL somewhere. You will need to find out where that object pulls the files from if at all - if not, then it is embedded in the DLL and I would contact the vendor.
You can find out where the DLL is located by searching for the object name (i.e. ETFramework11.WPLoginPage in the registry).
They are called COM components which is a spec different technologies can implement. I think most of the ASP world implemented them with a technology called ActiveX.
The file can theoretically reside anywhere. The system is told about the COM components through the "Regsvr32" command.
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