Asp. NET to JavaScript transfer variables two methods of implementation _ practical skills

Source: Internet
Author: User
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!

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.