ASP.NET: How to pass a value to a string from a local resource?
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 w开发者_如何学编程ant 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
string message = GetFromResourceFile();
string completeMessage = string.Format(message, "Name");
<asp:RequiredFieldValidator
ControlToValidate="textboxName"
runat="server"
ErrorMessage="<%$ string.Format(Resources:Error, 'textboxName') %>
ID="validatorName">
Or you could try the following in the code behind...
validatorName.ErrorMessage = string.Format(Resources.Error, "textboxName");
According to http://msdn.microsoft.com/en-us/library/fw69ke6f(v=vs.80).aspx
It should be
<asp:RequiredFieldValidator ControlToValidate="textboxName" runat="server" ErrorMessage="<%$ Resources:ResourceFileName, Error %> ID="validatorName">
Where ResourceFileName is the name of your resource file
精彩评论