The manager told me yesterday. Is there any way to make users unable to see JS and do not want users to modify JS files. In case of program confusion. I have never done this before, and I have never thought about this problem. I found it online today. Finally, there is a result.
Step 1: Create a project)
Find the AssemblyInfo. CS file and add the resource file to the file. Add the following code to the end of the document:
[Assembly: WebResource ("ClassLibrary1.JScript1. js", "application/x-javascript")]
ClassLibrary1 is the project namespace. If there is no namespace, you don't need to write it. You just need to write the file name.
Create a class file here because the demo I wrote is not too standard, the Class1
Code
Public class Class1: WebControl
{
Protected override void OnPreRender (EventArgs e)
{
If (this. Page! = Null)
{
If (manager_JSname = "JScript1 ")
{
ClientScriptManager manager1 = this. Page. ClientScript;
Manager1.RegisterClientScriptResource (typeof (Class1), "ClassLibrary1.JScript1. js ");
}
Else if (manager_JSname = "JScript2 ")
{
ClientScriptManager manager2 = this. Page. ClientScript;
Manager2.RegisterClientScriptResource (typeof (Class1), "ClassLibrary1.JScript2. js ");
}
}
Base. OnPreRender (e );
}
Private string manager_JSname;
Public string Manager_JSname
{
Get {return manager_type ;}
Set {manager_type = value ;}
}
}
Then write on the page file
Write on the page header
<% @ Register Assembly = "ClassLibrary1" Namespace = "ClassLibrary1" TagPrefix = "PC3" %>
Content Center
<PC3: Class1 runat = "server" ID = "class1" manager_JSname = "JScript1"> </PC3: Class1>