开发者

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 (i.e. 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>


Finally, I did this using server side code like follwong.

RVTest.ErrorMessage =MyLibrary.ValidationMessages.RequiredField;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜