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

I created a web page called server.aspx and an associated local resource file called server.aspx.resx. In the resource file, I defined the message "{0}". with a key mistake.

On my .aspx page, I access the line:

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

Now I want to pass a value, for example, the name of the "Name" text box to the resource string, so for errormessage it says "Name is required."

Is it possible to pass a value to a string?

Torben

+4
source share
3 answers
 string message = GetFromResourceFile(); string completeMessage = string.Format(message, "Name"); 
+1
source
 <asp:RequiredFieldValidator ControlToValidate="textboxName" runat="server" ErrorMessage="<%$ string.Format(Resources:Error, 'textboxName') %> ID="validatorName"> 

Or you can try the following in the code behind ...

 validatorName.ErrorMessage = string.Format(Resources.Error, "textboxName"); 
+1
source

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

-1
source

Source: https://habr.com/ru/post/1300978/


All Articles