开发者

ASP.NET: How to pass a value to a string from a local resource?

开发者 https://www.devze.com 2022-12-19 17:28 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号