Validation controls error message from Resource file and parameterized - asp.net

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

Related

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

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 "Κατάσταση"

How can i get the values of parameters from query string in aspx file?

Previously i passed the parameters to my page in a query string. Now, how am i supposed to get them and use them in my page ?
I tried this code and it doesn't work :
<asp:Label runat="server" ID="ShowParameter"><%# Request.QueryString["IDProduct"] %></asp:Label>
You need to use <%= Request.QueryString["IDProduct"] %>. # is used for databinding.
It also goes without saying that you should also check to make sure the query string is not null and that it actually exists. It is also generally not a good idea to directly output a query string like this for a number of reasons.

asp.net global resources error 'The resource object with key '' was not found'

I'm using asp.net global resource to try and implement a two language website, I added a simple resource in the global resource file called en-Us.resx that contains:
Password | Text
Email | Text
then implemented it to a textbox within the default page:
<asp:TextBox runat="server" ID="loginEmail" Text="<%$ Resources:en-US, Email %>"
></asp:TextBox>
but when ever I run the page on localhost I get this error:
The resource object with key '' was not found
I am using asp.net 4.0, what is the problem?
The format of resource files are ResourceName.culture.resx
Create a resource file in the App_GlobalResources folder called
Main.resx. This is for the default culture ( ie Invariant )
Then create a resource file Main.en-US.resx
This is where all the resources for en-US culture will live, and so on.
Main.resx
Main.en.resx
Main.en-US-resx
Main.en-AU.resx
Main.fr.resx
Main.fr-FR.resx
etc.
To access this from the webpage use the syntax
<%$ Resources:Main, Email %>
Don't worry around the culture, the system will work it out. It will exact match first ( en-US ), then work up to that's cultures parent ( en ), parent's parent ( Invariant ).
Change the name of "Main" to suit your needs
Change your file name to en-US.aspx.resx and try again. See this helps.
Try changing the build actions and see what happens. See here

<asp: > vs <input> Sending an email to user input email. ASP.NET VB

I have 2 pages, one is HTML and the other is ASPX. In the HTML I am able to get input from a user and then process a return email to them.
The HTML looks like this:
<input type="text" class="input" value="e-mail" id="txtEmail" name="contactEmail" onclick="SelectAll('txtEmail');" >
and I'm using the following in the method
Dim sResponseToName As String = Request.Params("contactEmail").ToString
This part of my page works perfect as someone sends me a request I am about to direct an email to their "contactEmail"
However, in my aspx page it looks like this:
<asp:TextBox ID="contact_Email" CssClass="inputtext1" runat="server">
and the method used is:
Dim sResponseToName As String = Request.Params("contact_Email").ToString()
but no email is sent to the input email address.... If I hard code a random email instead of Request.Params("contact_Email").ToString() it works fine. But for some reason I can not get to the inputted user address.
kinda stumped, I've tried a few things but no luck. How do I get the Request.Params to work in an aspx, and do I need to add something in <asp:TextBox....> to reference it.
Please help, thanks in advance.
The beauty of making the asp:TextBox a server control is that, within the server code, you have access to the actual object. So there's no need to deal with the request parameters, you can just access the TextBox object:
Dim sResponseToName As String = contact_Email.Text
You have to reference the TextBox object like this:
Dim sResponseToName As String = contact_Email.Text

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

Resources