简体   繁体   中英

Read validation message from external library

I created a Global Resource file for Error messages and I am attaching the associated message to the validator control as following.

  <asp:RequiredFieldValidator ID="RVTest" 
                        CssClass="ErrorMessage" runat="server" 
                        ErrorMessage="<%$ Resources:ErrorMessage, RequiredFieldTestKey %>" 
                        ControlToValidate="ReqFldTestTextbox"> </asp:RequiredFieldValidator>

This is working fine.

Now I am planning to move all the Global Resources to a different library let say MyResourceLibrary and created a resource file with name ErrorMessage . I have added the reference of the library to my ASP.NET project and trying to acces the message from my library as follwong.

 <asp:RequiredFieldValidator ID="RVTest" 
                        CssClass="ErrorMessage" runat="server" 
                        ErrorMessage="<%$ Resources: MyResourceLibrary.ErrorMessage, RequiredFieldTestKey %>" 
                        ControlToValidate="ReqFldTestTextbox"> </asp:RequiredFieldValidator>

But this is not working.

If your resource file is named the same as the page you are on (ie Default.aspx.resx)

You can add meta:resourcekey as so:

 <asp:RequiredFieldValidator ID="RVTest" 
                    CssClass="ErrorMessage" runat="server" 
                    meta:resourcekey="RequiredFieldTestKey" 
                    ControlToValidate="ReqFldTestTextbox"> </asp:RequiredFieldValidator>

最后,我使用follwong这样的服务器端代码来完成此操作。

RVTest.ErrorMessage =MyLibrary.ValidationMessages.RequiredField;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM