WebControls and client script path, webcontrols script
There are not many useful materials on the Internet. I excerpted the following content from an e-book:
The webControls configuration section has only one clientScriptsLocation attribute, which is used to specify the default storage path for ASP. NET client scripts. These files are the client functions required when the HTML code generates the ASPX page, such as smart navigation and client control verification.
<WebControls clientScriptsLocation = "/aspnet_client/{0}/{1}/"/>
The above code is the default content of <webControls>. The content of clientScriptsLocation is used to search for included scripts. The aspnet_client folder is automatically generated when you install ASP. NET in the following directory of the Web server. Two Placeholders are used to represent the name of the sub-folder, which may be changed in future ASP. NET versions. The first placeholder is always set to system_web. The second placeholder is the. NET Framework version number.
ASP. NET 4 does not use this folder to store client script files. In fact, the client script file is embedded into the system. web assembly as a resource. And inject it to the page through webresource. axd HTTP handler.
You can use the client script folder to save the script file used by the custom ASP. NET control.
It seems that this is actually abandoned and. NET Framework4.6 source code to view the webControlsSection class does not find any code to call this class, the monks tried to drag a verification control RequiredFieldValidator in a WebForm page, two more js scripts are referenced in the generated html code.
It can be concluded that the script file has been embedded into the assembly, and the corresponding resources are obtained through webresource. axd. In fact, the resources that can be embedded here refer not only to js, but also to image files.
Out of curiosity, I read the RequiredFieldValidator code,
One line of code is found to register the js file.
So I tried it myself.
ClientScript is an instance of ClientScriptManager. The js file name is js2.js. It must be included in the default namespace for this Assembly. The js2.js file is stored in the root directory of the website.
The object property is set in this way
Run the page to check that the generated html has a js reference.
I am wondering why namespace is not required for embedding Javascript in ValidatorBase. The MSDN example also explicitly adds a namespace. Is there another way to add a namespace to it?
However, it is still a bit unconvinced. Let's see how the original aspnet_client was obtained. Later we found that we can add the aspnet_client through aspnet_regiis. I tried to add it, but it didn't work. I still guessed whether the webControls configuration in the configuration file would affect the name of the generated folder. Later I found my guess wrong, and I still generated the aspnet_client. It seems that it is still used in. NET 1.0, and webresource. axd will be used in later versions. And now ASP. net mvc is also used in webForm. Now I still feel that it is not convenient to put js out and not embed it into the Assembly. I have modified js and want to compile the code.