Method 1:
Use a hidden control, give the value of the variable to the hidden control, and use JavaScript to find the value of the hidden control.
Please wait Doc ument. getelementbyid ("hidden Control ID"). Value // you can get the value of the hidden Control
Method 2:
In javascript:
VaR value = <% = num %>
Num is an attribute.
For example:
Public String num
{
Set {...}
Get {...}
}
Use alert ("<% = num %>") if the character variable is character-like alert ");
Num must be a public statement.
Interaction between JavaScript and Asp.net
Recently I was working on a Web back-end statistics system. I wanted to use Asp.net (CodeBinding), but found very difficult, some functions are easier to use JavaScript. In many cases, the interaction between C and S and database operations are involved. Javascript is relatively strong on the client control interface, but it is better to operate the database on the server than Asp.net.
The JS function is bound to the Asp.net control:
You can use the control. Attributes. Add (event, function), but I always report an error when I add the oncheckedchanged event to the checkbox.
Access the HTML control in Asp.net:
In one breath, all controls are replaced with HTML, and then runat = server is added to the control so that they can be referenced in Asp.net. Use (findcontrol (Control ID) as HTML control type). properties, such as (this. findcontrol ("ddlmonth") as htmlselect). selectedindex ......
Read the Asp.net variable from the HTML webpage.
In order to be able to read data in Asp.net in JS, we need to ensure that JS of the variable type in Asp.net can be distinguished. In fact, we can find a way to change it to string!
Second, declare the variable as public.
Use variable = "<% # Asp.net variable name %>"; in JS to get the variable value, such as VAR id = "<% # userid %> "; (Public String userid = "zhangsan" in Asp.net ";
We can use a good combination of JS and Asp.net to give full play to our respective strengths and use them in a targeted manner during the development process. We can really handle things!