Asp. NET custom control loading resource WebResource issues

Source: Internet
Author: User

Recent project with date control, want to put My97 resource file with TextBox into a DatePicker control, actually very simple opinion things, but still use a day more time, the main problem is to solve the problem of resource file loading. Through more than a day of effort, the following conclusions are drawn:

1, the custom control, generally just load the JS file, but all the resource files need to be registered in the AssemblyInfo.cs. The following are the specific methods:

1.1, the control registers the JS file code:

/// <summary>        ///Register JS/// </summary>        /// <param name= "E" ></param>        protected Override voidOnPreRender (EventArgs e) {Page.ClientScript.RegisterClientScriptInclude ("Wdatepicker", Getresurl ("Wdatepicker.js")); Base.        OnPreRender (e); }        /// <summary>        ///get the JS file path/// </summary>        /// <param name= "StrName" ></param>        /// <returns></returns>        Private stringGetresurl (stringstrName) {            returnPage.ClientScript.GetWebResourceUrl (GetType (),"Founder.Framework.Web.UI.WebControls.FIDatePicker.Resource."+strName); }

1.2. Register resource file code in AssemblyInfo.cs:

// My97 resource File [Assembly:webresource ("Founder.Framework.Web.UI.WebControls.FIDatePicker.Resource.WdatePicker.js  ""text/javascript")]        

2, if JS needs to refer to the CSS file by relative path, then the method of embedding the resource file into the DLL is not possible, can not find resources through the relative path, need to change the relative path to http://localhost/cmd2.0/WebResource.axd?d= Wlbeedvlp5nx1xffq8mumxnmsqtu_ Ihzyntdzsktqa4ojnpofsh9sqwwz8llxypbwpqcid9cfvyvg4i0ha1vnbhpjsbo6jmhbbium63wfc2gr6hyonixq9r03vb6jhowyzdi23srrj9hfi4sfmusv3 cai87ajd9qg28jy6ch1vc4talxqtipyd7fdaix8-hnnxrnqxggnjdlqxqpkemk2agkxbqqpwjveeocudfcybm1&t= 635400916300729758 this path.

Another way is to put the resource files in the Web site directory, through the relative path to access.

3. When encountering Http://localhost/cmd2.0/WebResource.axd?d=WLbEEdvLp5nx1XFfQ8MUMXnmSqTu_ Ihzyntdzsktqa4ojnpofsh9sqwwz8llxypbwpqcid9cfvyvg4i0ha1vnbhpjsbo6jmhbbium63wfc2gr6hyonixq9r03vb6jhowyzdi23srrj9hfi4sfmusv3 cai87ajd9qg28jy6ch1vc4talxqtipyd7fdaix8-hnnxrnqxggnjdlqxqpkemk2agkxbqqpwjveeocudfcybm1&t= 635400916300729758 This access to resources, you need to carefully look at the registration of resources where, is not the file name or path is not correct, if you really do not see, you can reflect the system.web way to parse this character, to see exactly which file is wrong. The specific code is as follows:

typeof (System.Web.UI.Page); // get page type            MethodInfo methods = Type. GetMethod ("decryptstring", BindingFlags.NonPublic | BindingFlags.Static); // get the decryption method            Object NULL );             Object  This . Txtoldvalue.text};             this. Txtnewvalue.text = methods. Invoke (obj, args). ToString ();

4, decryption is a need to pay attention to two questions:

4.1, the decrypted code needs to be in the same site, not independent of the site to decrypt the error.

4.2, the latest 4.0 version of the System.Web.dll decryptstring method has two parameters, do not know how to use, anyway I test n long without fruit.

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.