views:

53

answers:

2

Hello,

I have created a webpage called server.aspx and the related local resource file called server.aspx.resx. In the resourcefile I defined the message "{0} is required." with the key Error.

In my .aspx page I access the string:

<asp:RequiredFieldValidator ControlToValidate="textboxName" runat="server" ErrorMessage="<%$ Resources:Error %> ID="validatorName">

Now I want to pass a value, for example the name of the textbox 'Name' to the resource string, so that the errormessage is "Name is required."

Is there any possibility to pass a value to the string?

Torben

A: 
string message = GetFromResourceFile();
string completeMessage = string.Format(message, "Name");
Gerrie Schenck
Okay, but this is only possibile in code behind? But how can I do this in the .aspx page?
Torben H.
+1  A: 
<asp:RequiredFieldValidator 
    ControlToValidate="textboxName" 
    runat="server" 
    ErrorMessage="<%$ string.Format(Resources:Error, "textboxName") %> 
    ID="validatorName">
Sohnee
When I try it this way, I get the error message, that the server tag is not well-formed.
Torben H.
Try with single quotes, i.e. ErrorMessage='<%$ string.Format(Resources:Error, "textboxName") %>'
Jakob Gade
Didn't work. With single quotes I get the error "The expression prefix 'string.Fornat (Resources' was not recognized."
Torben H.