Getting text from the Resource file in asp.net 4

痴心易碎 提交于 2019-12-02 00:55:28

问题


i have an asp.net webpage, which contains a label, now i want to get the text property of the label from the localresource file, i have a .resx file under App_LocalResources folder, which contains Name as UserNameLabel.Text and Value as User Name now in my aspx file i am using Label control like this

<asp:Label ID="UserNameLabel" runat="server" resourcekey="UserNameLabel"></asp:Label>

but i cannot get the text on the Label, can anyone tell me the correct way to add the Text Property from resource file


回答1:


First you need to create appropriate structure inside web project. In this case I will be using Default.aspx:

Take notice I have placed Default.aspx.resx file inside App_LocalResources.

Next enter new item inside Default.aspx.resx like this:

The important thing is you need to set Text property (UserNameLabel.Text)

And finally here is aspx code:

<asp:Label ID="UserNameLabel" runat="server" meta:resourcekey="UserNameLabel"></asp:Label>

I have used meta:resourcekey to link to appropriate resource key.



来源:https://stackoverflow.com/questions/13849015/getting-text-from-the-resource-file-in-asp-net-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!