Reputation: 175
I have created resource file under Test Project but not under App_GlobalResources.How can i set button text using resource file. For eg:
<asp:Button ID="btnTest" runat="server" Text="<%:TestProject.TestResource.Test%>" />
When i use above code i am getting blank text in the button.
Note - I don't want to set text at code behind.How can i achieve this at aspx file.
Thanks for the help
Upvotes: 9
Views: 16037
Reputation: 12713
Assuming your Resourcesfile is called:
/App_GlobalResources/TestResource.resx
And the resource string Test
, this should work:
<asp:Button ID="btnTest" runat="server" Text="<%$ Resources: TestResource, Test %>" />
Upvotes: 15
Reputation: 2014
The best way to provide resources for your pages would be using custom resource provider in your case because you dont want to use App_GlobalResources, and store all the resource data in Viewdata or Session data in codebehind and retrieve them and associate that to your button text in your aspx page.
Here is an msdn article on it (this article also explains to use resources from external assembly):
http://msdn.microsoft.com/en-us/library/aa905797.aspx
Hope that helps.
Upvotes: 0
Reputation: 7006
In your Resource files say you have something like this
MyButtonText
------> WhateverText
Then you can set the Text as follows
<asp:Button ID="mybtn" runat="server" Text="<%$Resources:MyButtonText%>"
Upvotes: 0