Client scripts and server scripts are not very clear for a long time. Not to mention understanding deeply. Now let's try to describe your thoughts so that you can correct them.
Understanding web programming is mainly about understanding server scripts and client scripts. Most people attach great importance to server scripts. However, various client scripts are ignored. Because client scripts can complete functions that cannot be completed by server scripts. I want to focus on the following aspects:
(1) display the message dialog box on the client
(2) open a new window (window object)
(3) communication between windows
(4) play simple animations
(5) Write a custom client verification script
I think there may be other features. I personally think that the client-side script functions will be constantly enhanced and expanded, because this is in line with the trend of constantly emphasizing individual intelligence in the system. In the ASP. NET era, we are more comfortable with the development of server scripts, but the compilation of client scripts does not seem to have changed significantly with ASP. So how can I write client scripts? In other words, how does one send a script to a browser? Below I will list some methods:
1. directly write the client script in the aspx file:
<SCRIPT type = "text/JavaScript">
Function showalert (){
Alert ("hello ");
}
</SCRIPT>
This is also a commonly used javacript method in ASP. We can see that this is a function in the pop-up message window. Generally, it is placed in the
Ii. Use server scripts to write client scripts
Note that this method is obviously inefficient. However, in ASP, the interaction between the server and client scripts is of great significance. It is similar in ASP. NET.
<SCRIPT type = "VB" runat = "server">
Sub showalert ()
With response
. Write ("<SCR" & "ept Language =" "JavaScript" ">" & system, enviornment. newline)
. Write ("alert ('Hello! '); "& System, enviornment. newline)
. Write ("</scr" & "ept> ")
End
End sub
</SCRIPT>
We can see that although the server information (such as sessionid) is not transferred to the client, we can still clearly see how to use server scripts to write client scripts.
3. Use background code to write client scripts
This is a mechanism provided by ASP. NET. The attribute of the object is used to complete the process. For example, the click event of button1 can be written as follows:
Button1.attributes. Add ("onclick", "alert ('hello ');")
4. Use registerclientblock () to write client scripts
This is a new function added after ASP. NET is entered. The following example shows how to pass the server variables to the client scripts.
<SCRIPT type = "VB" runat = "server">
Sub page_load (sender as object, e as eventargs)
Dim s as string = "<script language = JavaScript>"
S + = "Var session = '" & session. sessionid &"';"
S + = "</scept>"
Registerclientscriptblock ("script", S)
End sub
</SCRIPT>
The principle is as follows: sessionid is a server-side script, which is first written into the client-side script string. Then, use registerclientscriptblock to write the script after the _ viewstate control hidden in the output stream. Finally, read the script on the client to get the sessionid variable value. This completes the interaction between client scripts and server scripts.
In short, client scripts are rich and colorful and must be carefully studied.
References:
Http://www.loveyuki.com/blogview.asp? Logid = 173
Http://www.moon-soft.com/doc/44851.htm