3

Please help me I am struggling with one issue that I am not very much familiar with that is using resource file in asp.net.

I am working on code in asp.net which is checking multiple if conditions in business layer class and on the basis of if conditions, it should display pargraphs of information text to users in either english or french. The text contains date formatting functions, anchor tags and onclick events of anchor tags.

Example is:

if((a=b)&&(c=a))
{
    <p>
    <b>mpus odio feugiat ac. Nulla blandit dolor vitae</b><br />
  ccumsan in sit amet erat. Quisque ac nulla tempus, maximus risus sed, dapibus arcu. Nullam nec enim tellus.
    <a href="/paycash">Click here </a>ctus aliquam, eu lacinia.
eget nibh est. In eu bibendum mi. Quisque quis est a risus tincidunt gravida. Morbi id finibus magna. Aene
  </p>
   <p>m et lectus aliquam, eu lacinia elit viverra. Donec a libero sed sem vestibulum posuere. Proin tristique enim purus <a href="http://a.a.com">click here</a>s est a risus tincidunt gravida. Morbi. m et lectus aliquam, eu lacinia elit viverra. Donec a libero sed sem vestibulum posuere. Pr</p>
  <p>
    <b><a name="dhjs"></a> Nulla blandit dolor vitae</b><br />
    <a target="_blank" onclick="window.open('.a/c/c, '_blank','width=1257,height=895'); return false" href="s/d/d/dd.com">Click here</a>  Donec a libero sed sem vestib
   </p>
   <p>tudin non lacus. In hac habitasse platea dictumst. Donec molestie efficitur ante eget  <%= FormatDateTime(oRs("ExpiryDate"),1) %>tudin non lacus. In hac habitasse platea dictumst. Donec molestie efficitur ante eget 
}
else if
{
}

I want to store this result text to resource file. Such that, if a condition is true, I should pass the keys of resource file to aspx file. But, I am sure how to achieve this? Should I store the complete paragraph into resource file and pass a single key back to label in aspx file then, how would anchor tag and functions would work? OR should I break it into parts? If I break it into different keys, how should I pass the resource keys back to aspx file and what should I do with date formatting functions and hyperlinks?

Another question is on passing back result to aspx file, should I display paragraphs of text in label text?

Please help.

MethodMan
  • 18,625
  • 6
  • 34
  • 52
LAnand
  • 33
  • 6

1 Answers1

2

You should break it up.

Static text resources should go in your .resx file, and can be retrieved using a bit of c# code (e.g. GetString). Normally you should not store code in a resource file, as it will not be validated, compiled, or minified in there; plus, there isn't much point, as code does not need any localization support (Javascript in German is exactly the same as Javascript in English).

ASP markup and inline server-side code should go in .aspx files. Also, static HTML should usually go into the .aspx file too (just omit the runat="server" tag). It is OK to store some text there if you think your application will never need multi-lingual support, but it is better to use resource files if you can.

Javascript code in the best case should go in separate .js files and referenced from your page, e.g. like this

<script src="js/YourExternalJQueryScripts.js"></script>

If you absolutely require inline Javascript, you can include it in the .aspx file, or add it via c# codebehind, using the ClientScriptManager.

John Wu
  • 50,556
  • 8
  • 44
  • 80