Variable Interaction Between the server and the client

Source: Internet
Author: User

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!

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.