Use of Asp.net resource files

Source: Internet
Author: User

1. create a resource project 2. create a javascript file. The JScript1.js content is: function test () {alert (Res. failUser);} note that the property of the javascript file is "embedded resource" 3. create a resource file ScriptResource. resx: add the Resource name FailUser value Wrong user name or password! Create resource file ScriptResource. zh-CN.resx Add Resource Name FailUser value error username and password! 4. Add two references: System. Web. Extensions. dll, System. Web. Extensions. Design. dll4. register the resource file class.

[assembly: System.Web.UI.WebResource("LocalScriptResource.JScript1.js","application/x-javascript")][assembly: System.Web.UI.ScriptResource("LocalScriptResource.JScript1.js","LocalScriptResource.ScriptResource","Res")]
Save this code to: Assembly. cs

5. Compile the dynamic link library 6. Add scriptmanager on the asp.net Interface
Code
  <Asp: ScriptManager ID = "ScriptManager1" runat = "server" EnableScriptLocalization = "true" EnablePageMethods = "true">
<Scripts>
<Asp: ScriptReference Assembly = "LocalScriptResource" Name = "LocalScriptResource. JScript1.js"/>
</Scripts>
</Asp: ScriptManager>

 

7. js end call function check () {// use Res directly to call alert (Res. FailUser);} 8.cs file call
  ResourceManager rm=new ResourceManager("LocalScriptResource.ScriptResource",Assembly.Load("LocalScriptResource"));
    rm.GetString("FailUser");

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.