In ASP, we can easily implement interaction between server variables and clients. So how can we implement it in. Net?
We know that we can also use <% = var %> On the page in Asp.net. From this point of view, we assign the server value to the variable VAR. But here is a note-we must first define this variable in. CS (or. VB) corresponding to the page. This variable cannot be defined as private. Because the. CS file is the default base class of the. aspx file. If we define the variable as private, we will not use this value in. aspx.
For example, we write the following JavaScript statement into the page:
<Script language = JavaScript>
VaR I;
I = <% = var %>;
Function window. onload ()
{
Alert ("I =" + I );
}
</SCRIPT>
In the server code, we first define this var;
Protected int var;
Var = 111;
When the page is executed, JavaScript will get the correct value.
Here is just a simple example. Complicated and flexible!