Beginner
Beginner

Reputation: 175

How to set button text using resource file

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

Answers (3)

Remy
Remy

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

Alagesan Palani
Alagesan Palani

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

Priyank Patel
Priyank Patel

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%>"

Refer to Sample Article

Upvotes: 0

Related Questions