Method 1:
Use a hidden control, give the value of the variable to the hidden control, and then use JavaScript to find the value of the hidden control
Window.document.getElementById ("Hide the ID of the control"). Value//This will get the values of the hidden control
Method 2:
In javascript:
var value=<%=num%>
Num If a property
Such as:
Copy Code code as follows:
Public String Num
{
Set{...}
Get{...}
}
If the character variable is a character type like alert (), use alert ("<%=Num%>").
and num must be public.
the interaction between JavaScript and asp.net
The recent Web background statistics system, which would have all been implemented with ASP.net (code binding), was found to be difficult, with some features still easier to use JavaScript. Many of these involve the interaction between C and S as well as database operations, JavaScript in the client control interface is strong, but the server to manipulate the database or asp.net better ah.
The JS function is bound to the ASP.net control:
With the control. Attributes.Add (event, function) is OK, but I always make an error when adding oncheckedchanged event to the checkbox.
To access HTML controls in asp.net:
In a rage, replace all controls with HTML, and then add Runat=server to the controls so they can be referenced in asp.net. With (FindControl (control ID) as HTML control type). property, such as (this. FindControl ("Ddlmonth") as HtmlSelect). SelectedIndex ...
Reading asp.net variables in an HTML web page
In order to be able to read in the ASP.net data in JS, to ensure that the type of variable js asp.net can be distinguished, in fact, to find ways to become a string on the won Bai!
Second, declare the variable to be public.
Use variables in js = "<% #asp. NET variable name%>"; Can get the value of the variable, such as var id = "<% #userid%>"; (public string userid = "Zhangsan" in asp.net);
can use JS and asp.net good combination, play their strengths, in the development process of targeted use, really can do the work times Ah!